200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > android-设置状态栏与标题栏背景

android-设置状态栏与标题栏背景

时间:2019-06-28 01:45:01

相关推荐

android-设置状态栏与标题栏背景

通过下面记步,可以设置应用的title与系统的通知状态栏系统的背景颜色:

1、 设置系统Theme

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"><item name="windowActionBar">false</item><item name="windowNoTitle">true</item><!-- Customize your theme here. --><item name="colorPrimary">@color/colorPrimary</item><item name="colorPrimaryDark">@color/colorPrimaryDark</item><item name="colorAccent">@color/colorAccent</item></style>

2、 在布局文件中增加v7的toolBar

<android.support.design.widget.AppBarLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:theme="@style/AppTheme.AppBarOverlay"><android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorPrimary"app:popupTheme="@style/AppTheme.PopupOverlay" /></android.support.design.widget.AppBarLayout>

3、 在Activity设置toolbar

@TargetApi(Build.VERSION_CODES.M)protected void initToolbar() {mToolbar = (Toolbar) findViewById(R.id.toolbar);if(mToolbar == null) {return;}mToolbar.setTitle(getTitle());setSupportActionBar(mToolbar);//if (android.os.Build.VERSION.SDK_INT >= 21) {Window window = getWindow();window.setStatusBarColor(getStatusBarColor());}else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {final SystemBarTintManager tintManager = new SystemBarTintManager(this);tintManager.setStatusBarTintEnabled(true);tintManager.setStatusBarTintColor(getStatusBarColor());}}

还可以设置屏幕底部的虚拟按键的背景及全屏(待处理)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。