android设置无标题栏 、 状态栏

设置无标题栏,状态栏的方式有三种

第一种:在java文件中修改(注意:如果改成隐藏标题栏,那么MainActivity必须继承Activity)

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏

        setContentView(R.layout.activity_main);
   }
}

第二种:在AndroidManifest中修改(我改的时候会报错,不知道是不是这个方法不能用了

 <activity android:name=".MainActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" // 不显示应用程序标题栏,并全屏 >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

第三种:自定义无标题栏 Theme(注意:记得AndroidManifest下引用

修改下图中的文件

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> //设置无状态栏theme
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

    </style>

</resources>

这里我列一下各种样式方便大家使用和修改:

Theme.Dialog : //Activity显示为对话框模式
Theme.NoTitleBar : //不显示应用程序标题栏
Theme.NoTitleBar.Fullscreen : //不显示应用程序标题栏,并全屏
Theme.Light : //背景为白色
Theme.Light.NoTitleBar : //白色背景并无标题栏
Theme.Light.NoTitleBar.Fullscreen : //白色背景,无标题栏,全屏
Theme.Black : //背景黑色
Theme.Black.NoTitleBar : //黑色背景并无标题栏
Theme.Black.NoTitleBar.Fullscreen : //黑色背景,无标题栏,全屏
Theme.Wallpaper : //用系统桌面为应用程序背景
Theme.Wallpaper.NoTitleBar : // 用系统桌面为应用程序背景,且无标题栏
Theme.Wallpaper.NoTitleBar.Fullscreen : //用系统桌面为应用程序背景,无标题栏,全屏
Theme.Translucent : //透明背景
Theme.Translucent.NoTitleBar : //透明背景并无标题
Theme.Translucent.NoTitleBar.Fullscreen : //透明背景并无标题,全屏
Theme.Panel : //面板风格显示
Theme.Light.Panel : //平板风格显示

然后修改AndroidManifest。

 <application
        android:allowBackup="true"
        android:icon="@drawable/bb1"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">  // 使用这个Theme
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

好了,更改标题栏状态栏样式的方法我就介绍到这了,希望能帮助到你们。

猜你喜欢

转载自blog.csdn.net/z1web/article/details/84332812