Android如何更改概览标签颜色?
我有我的style.xmlAndroid如何更改概览标签颜色?,android,android-5.0-lollipop,Android,Android 5.0 Lollipop,我有我的style.xml <style name="AppTheme" parent="Theme.AppCompat.Light"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android: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>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/container_body"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
如果您使用的是tooldbar,则可以通过活动更改颜色。还有风格,但我建议你从活动中改变 在下面的代码中,工具栏id是
ab_tool
,您可以用xml中的任何内容来表示它
在您的活动中保留以下代码
Toolbar toolbar = (Toolbar) findViewById(R.id.ab_tool);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(Color.WHITE);
如果ActionBar没有工具栏,则需要更改ActionBar文本视图文本颜色
int titleTextViewResourceID = getResources().getIdentifier("action_bar_title", "id", "android");
TextView txtActionBarTitle = (TextView) findViewById(titleTextViewResourceID);
txtActionBarTitle.setTextColor(Color.WHITE);
更新
AFAIK是最新应用程序上显示的默认行为
默认情况下,标题颜色是根据actionbar或toolbar样式中给定的colorPrimary
从内部获取的
系统将根据colorPrimary
在内部提供标题颜色
系统会将带有关闭按钮和应用程序图标的ActionBar放在最新的应用程序缩略图中,即使在您的应用程序中,您也不会使用ActionBar、工具栏样式的任何东西。
案例1
在这里,如果您给出了您所给出的暗红色(红色比例更大),则在最近的应用程序中,即使您在活动中从xml或运行时为标题文本提供白色,也会将黑色作为标题颜色
如何将其更改为白色
使用下面的颜色组合在最新的应用程序actionbar上获得白色
<color name="slider_bg_primary">#ff5b45</color>
<color name="slider_bg_primary_dark">#FF5722</color>
<style name="AppThemeSliderToolbar" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/slider_bg_primary</item>
<item name="colorPrimaryDark">@color/slider_bg_primary_dark</item>
</style>
#ff5b45
#FF5722
@颜色/滑块\u背景\u主
@颜色/滑块\u背景\u主\u暗
在清单中为上述所有情况的活动使用AppThemeSliderToolbar
主题
您是在不使用
工具栏的情况下使用actionbar还是在使用工具栏的情况下使用actionbar?您希望哪个标签为黑色?带有“Hello World!”文本或actionbar标题的内容?#FC7E0D#FC7E0D更改此内容color@user1140237只有工具栏和AppCompatActivity@user1140237书名actionbar@StarSquad在哪里应用工具栏标题颜色<代码>工具栏.setTitleTextColor(颜色.白色)代码>@user114027我申请了,但这不起作用,我删除了这段代码。@StarSquad我想你是在问为什么它在最近的应用程序中不显示白色?
Toolbar toolbar = (Toolbar) findViewById(R.id.ab_tool);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(Color.WHITE);
int titleTextViewResourceID = getResources().getIdentifier("action_bar_title", "id", "android");
TextView txtActionBarTitle = (TextView) findViewById(titleTextViewResourceID);
txtActionBarTitle.setTextColor(Color.WHITE);
<color name="colorPrimary">#FC7E0D</color>
<color name="colorPrimaryDark">#E07514</color>
<color name="colorAccent">#EF4B07</color>
<style name="AppThemeSliderToolbar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/slider_bg_primary</item>
<item name="colorPrimaryDark">@color/slider_bg_primary_dark</item>
</style>
<style name="AppThemeSliderToolbar" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/my_primary_light</item>
<item name="colorPrimaryDark">@color/slider_bg_primary_dark</item>
</style>
<color name="slider_bg_primary_dark">#FF5722</color>
<color name="my_primary_light">#B3E5FC</color>
<color name="slider_bg_primary">#ff5b45</color>
<color name="slider_bg_primary_dark">#FF5722</color>
<style name="AppThemeSliderToolbar" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/slider_bg_primary</item>
<item name="colorPrimaryDark">@color/slider_bg_primary_dark</item>
</style>