1. 全屏
1.1 代码中设置
requestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏标题
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);// 设置全屏
setContentView(R.layout.activity_main);
注意:setContentView一定要写在设置全屏后边
1.2 AndroidManifest.xml文件中设置
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name="com.scwindow.utility.CrashApplication" >
在res文件下的values文件下styles.xml文件中,定义一下AppTheme
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
2. 设置屏幕常亮
2.1 代码设置
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
注意:放置在setContentView(R.layout.activity_main)上面。
3. 强制横屏
3.1 代码设置
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
3.2 AndroidManifest.xml文件中针activity设置
android:screenOrientation="landscape"
4. 冷启动时白屏问题解决
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:background">开机后的图片</item>
</style>
备注:该操作只是把开机白屏替换成了开机的第一张图片,给用户的感觉是第一时间进入了软件,实际上并没有解决冷启动速度慢的问题。