2016-02-03 83 views
2

我有我的style.xmlAndroid如何更改概览标签颜色?

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

这是我的概述 image

我想让我的标签白色,但如何?我知道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> 
+0

您使用的动作条不'ToolBar'或'ToolBar'? – user1140237

+0

哪个标签你想作为黑色?与“世界您好!”的一个!文本或操作栏的标题? – user1140237

+0

#FC7E0D <颜色名称= “colorPrimary”>#FC7E0D改变这种颜色文档:http://developer.android.com/training/material/theme.html)或使用默认情况下为白色的灯光主题。 – Madhur

回答

0

如果使用tooldbar比你可以从你的活动变色。风格也,但我会建议你改变它从活动。

在下面的代码工具栏ID为ab_tool你可以在你的xml中给它任何东西 在你的Activity中保留下面的代码。

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

如果动作条是没有工具栏不是需要改变动作条TextView的文本颜色

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

更新

据我所知这是这是显示在最近的应用程序的默认行为。

标题颜色默认情况下,从内部基于风格给出了动作条或工具栏

系统会给内部基于colorPrimary标题颜色colorPrimary服用。

系统就会把动作条与关闭按钮&应用程序图标在最近的应用程序在你的应用程序没有使用动作条,工具栏风格的东西,甚至缩略图。

案例1 在这里,如果你给深颜色偏红的颜色(红色规模以上),你的问题比它会采取黑色颜色在最近的应用程序即使一标题颜色给您将白色赋予xml中的标题文本或活动中的运行时。

Sample Image

<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 如果你给光色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> 

Sample Image case2

你怎么能更改下面的颜色组合White颜色 用得到白色的最新应用程序动作条。

<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主题舱单活性高于一切的情况下

White Color TItle

+0

不工作你的第一个解决方案;( –

+0

@StarSquad张贴您的活动代码和xml文件 – user1140237

+0

我编辑我的帖子 –

相关问题