簡體   English   中英

Android如何更改概述標簽顏色?

[英]Android how to change overview label color?

我有我的style.xml

<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" />

和我的color.xml:

<color name="colorPrimary">#FC7E0D</color>
<color name="colorPrimaryDark">#E07514</color>
<color name="colorAccent">#EF4B07</color>

這是我的概述 圖片

我想將標簽設為白色,但是怎么做? 我知道TaskDescription,但是在這種情況下taskdescription對我沒有幫助。

我的manifest.xml:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity.class:

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    private Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        navigationView.getMenu().performIdentifierAction(R.id.nav_main, 0);
    }

    ...other code...

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,則可以從活動中更改顏色。 和風格,但我建議您從活動中更改它。

在下面的代碼中, ab_tool ID是ab_tool您可以在xml中為其提供任何內容,並在Activity中保留以下代碼。

Toolbar toolbar = (Toolbar) findViewById(R.id.ab_tool);
setSupportActionBar(toolbar);        
toolbar.setTitleTextColor(Color.WHITE);

如果ActionBar沒有工具欄,則需要更改ActionBar TextView文本顏色

 int titleTextViewResourceID = getResources().getIdentifier("action_bar_title", "id", "android");
        TextView txtActionBarTitle = (TextView) findViewById(titleTextViewResourceID);
        txtActionBarTitle.setTextColor(Color.WHITE);

更新

AFAIK是默認行為,顯示在最新的應用程序上。

默認情況下,標題顏色是從內部根據colorPrimary ,以actionbar或工具欄的樣式指定

系統將基於colorPrimary內部提供標題顏色。

系統會在最近使用的應用程序縮略圖中將帶有關閉按鈕和應用程序圖標的ActionBar放置在最新的應用程序縮略圖中,即使在您不使用ActionBar的應用程序中,工具欄樣式也是如此。

情況1在這里,如果您給出的顏色是帶紅色的(紅色標度更大),即使您將xml或運行時中的標題文本賦予白色,在最新的應用程序中它也會將黑色作為標題顏色。活動。

樣本圖片

<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>

情況2如果為color賦予淺色, colorPrimary系統內部將采用黑色。

<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>

樣本圖片案例2

如何將其更改為白色使用以下顏色組合在最新的應用程序操作欄上獲得白色。

<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>

最重要的情況是清單中的活動使用了AppThemeSliderToolbar主題

白色標題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM