第一种:代码设置
//在全局视图中,
public class WLBaseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setWindowStatusBarColor(R.color.hong_bg_color);
//默认都是竖屏的
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
/**
*
* @param isPortrait
* 设置页面横竖屏或者竖屏
*/
protected void setPortrait (boolean isPortrait){
if (isPortrait){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}else{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
/**
*
* @param isFullscreen
* 设置全屏显示
*/
protected void setFullscreen(boolean isFullscreen){
if (isFullscreen){
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}else{
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
}
/**
*
* @param colorResId
* 状态栏将显示为纯净的颜色,没有渐变效果
*/
protected void setWindowStatusBarColor(int colorResId){
WLStatusBarUtils.setWindowStatusBarColor(this,colorResId);
}
第二种:在AndroidManifest.xml中设置样式
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".MyAPP"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
<!--这个样式点进去。-->
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<!-- Base application theme.进来之后 -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. 这里面的三个颜色 可以更改成你APP的主题颜色。自己设置需要的颜色 -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!--加上这个-->
<item name="windowNoTitle">true</item>
</style>