Android Activity 设置全屏的方法如下:
1.代码设置:
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);//要放到加载布局文件代码之前
initView();
initData();
initListener();
}
2.清单文件中设置:
<activity
android:name=".PlayerActivity"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
在清单文件中注册Activity时,使用 Theme.NoTitleBar.FullScreen 这一主题。
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
3.定义style样式:
<style name="full_screen_style">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
在res/values/styles文件中定义一个全屏的style样式
下面使用该样式:
<activity
android:name=".PlayerActivity"
android:screenOrientation="landscape"
android:theme="@style/full_screen_style"/>
清单文件中注册该activity时在theme属性中使用该样式即可
4.创建theme.xml文件:
其实它和 3定义style样式是相同的,只不过把style样式定义在了theme.xml文件中而已。
在res/values文件夹下创建theme.xml文件,在theme.xml文件中定义一个style主题样式
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="full_screen_theme">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
使用该样式:
<activity
android:name=".PlayerActivity"
android:screenOrientation="landscape"
android:theme="@style/full_screen_theme"/>