[Android Studio] 顶部标题栏的隐藏和显示、标题修改

1、顶部标题栏的隐藏:

在我们的project工程下,找到“values”文件夹下的“themes.xml”或“styles.xml”文件(文件位置一致,后者优先级更高),然后把以下代码

<style name="Theme.Intelligent_agriculture" parent="Theme.MaterialComponents.DayNight.DarkActionBar">

修改为:

<style name="Theme.Intelligent_agriculture" parent="Theme.MaterialComponents.DayNight.NoActionBar">

//只需要把DarkActionBar修改成NoActionBar
//至于其他代码,保持原来即可

2、顶部标题栏的显示:

只需要把上述的过程反过来即可

“themes.xml”文件位置,如下图:

结果图如下:

                     

 3、顶部标题栏的标题修改:

首先,先打开“manifests”文件夹下的“AndroidManifest.xml”文件,设置主启动界面的label标签

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="智慧农业管理"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Intelligent_agriculture">
        <activity
            android:name=".new_farming"
            android:exported="false"
            android:label="农事记录">
        </activity>
        <activity
            android:name=".MainActivity"
            android:exported="true"        //标志为主启动界面
            android:label="智慧农业管理">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>



//通过:label标签修改
//如果主启动界面没有设置label标签,则APP的名称为application标签的label
//非主启动的Activity没有设置label标签的情况下,默认显示为APP的名称

 “AndroidManifest.xml”文件位置,如下图:

猜你喜欢

转载自blog.csdn.net/zhou_ge1/article/details/124342013