2016-05-17 11 views
1

私は自分のコードに固執しています。 navigationDrawerの "Title"テキストの色をどこに設定するのかはわかりません。navigationDrawerで項目タイトルの色を設定する方法は?

<android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:background="#000" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:layout_gravity="start" 
     app:headerLayout="@layout/header" 
     app:itemTextColor="your color" 
     app:menu="@menu/drawer" /> 

アプリ:itemTextColor =「あなた色」は唯一のインポート、ギャラリーなどのように、各項目を変更しますが、は、上の行との、textColorを伝え変更する方法?

写真2(濃い青色)は私のプロジェクトでのようです。私は自分のプロジェクトで「どこかで」色を白に設定しました。

enter image description here

enter image description here

あなたは私の問題を見つけることができますか?現在、私の "タイトル" テキストが

nav_header_main.xml

<ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     android:src="@android:drawable/sym_def_app_icon" 
     /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/nav_header_vertical_spacing" 
     android:textColor="@color/whiteGray" 
     android:text="@string/app_name" 
     /> 


</LinearLayout> 

activity_main.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" 
     > 

     <include 
      layout="@layout/app_bar_main" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <android.support.design.widget.NavigationView 
      android:id="@+id/nav_view" 
      android:background="@color/nav_drawer_background" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:fitsSystemWindows="true" 
      app:menu="@menu/activity_main_drawer" 
      app:headerLayout="@layout/nav_header_main" 
      app:itemTextColor="@color/nav_drawer_text" /> 

     <android.support.design.widget.NavigationView 
      android:id="@+id/nav_right_view" 
      android:background="@color/nav_drawer_background" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="end" 
      android:fitsSystemWindows="true" 
      app:menu="@menu/activity_main_right_drawer" 
      app:itemTextColor="@color/nav_drawer_text" /> 


    </android.support.v4.widget.DrawerLayout> 
..白です

app_bar_main.xml

<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" 
     app:popupTheme="@style/AppTheme.PopupOverlay" 
    /> 

</android.support.design.widget.AppBarLayout> 

<include layout="@layout/content_main" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    /> 

値/ style.xml

<style name="WelcomeDialogTitle"> 
     <item name="android:gravity">center_horizontal</item> 
    </style> 

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <item name="android:windowBackground">@color/darkblue</item> 
     <item name="colorPrimary">@color/transparent</item> 
     <item name="colorPrimaryDark">@color/darkblue</item> 
     <item name="colorAccent">@color/darkblue</item> 
    </style> 

    <style name="AppTheme.NoActionBar" parent="@style/Theme.AppCompat"> 
     <item name="android:windowBackground">@color/darkblue</item> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> 
    <item name="colorPrimary">@color/transparent</item> 
    <item name="colorPrimaryDark">@color/transparent</item> 
    <item name="colorAccent">@color/transparent</item> 
    </style> 

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> 
    <item name="android:windowActionBarOverlay">true</item> 
    <item name="windowActionBarOverlay">true</item> 
    </style> 

    <style name="CustomTheme" parent="@android:style/Theme.Black"> 
     <item name="android:listViewStyle">@style/CustomListView</item> 
     <item name="android:textViewStyle">@style/CustomTextView</item> 
    </style> 

    <style name="CustomListView" parent="@android:style/Widget.ListView"> 
     <item name="android:textColor">#000000</item> 
     <item name="android:fastScrollEnabled">true</item> 
    </style> 

    <style name="CustomTextView" parent="@android:style/Widget.TextView"> 
     <item name="android:textColor">#000000</item> 
     <item name="android:textSize">17sp</item> 
     <item name="android:padding">1dp</item> 
    </style> 

    <style name="TitleTextStyleLarge"> 
     <item name="android:gravity">left|center</item> 
     <item name="android:shadowColor">@color/white</item> 
     <item name="android:textAppearance">?android:attr/textAppearanceMedium</item> 
     <item name="android:textColor">@color/white</item> 
     <item name="android:textSize">18sp</item> 
    </style> 

    <style name="TitleTextStyle"> 
     <item name="android:gravity">left|center</item> 
     <item name="android:textSize">18sp</item> 
     <item name="android:layout_width">0dp</item> 
     <item name="android:layout_height">fill_parent</item> 
     <item name="android:layout_marginLeft">5dp</item> 
     <item name="android:layout_weight">1</item> 
     <!-- <item name="android:shadowColor">@color/white</item> --> 
     <item name="android:textColor">@color/white</item> 
    </style> 

    <style name="BarTitleStyle"> 
     <item name="android:background">@drawable/bg_list_topbar</item> 
     <item name="android:layout_height">33dp</item> 
     <!-- <item name="android:shadowColor">@color/white</item> --> 
     <item name="android:layout_width">fill_parent</item> 
    </style> 

    <style name="BarTitleProgressStyle"> 
     <item name="android:background">@drawable/bg_list_topbar</item> 
     <item name="android:layout_height">27dp</item> 
     <item name="android:layout_width">27dp</item> 
     <item name="android:layout_marginBottom">1dp</item> 
     <item name="android:layout_marginRight">5dp</item> 
     <item name="android:layout_marginTop">1dp</item> 
     <item name="android:layout_gravity">center</item> 
     <item name="android:gravity">center_vertical|center_horizontal</item> 
    </style> 

</resources> 

私の活動のテーマ

<activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" 
      android:theme="@style/AppTheme.NoActionBar" 
      > 
      <meta-data 

引き出し。XML

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

    <group android:checkableBehavior="single"> 
     <item 
      android:id="@+id/nav_search" 
      android:title="@string/LabelSearchTabTitle" /> 
     <item 
      android:id="@+id/nav_wiki" 
      android:title="@string/LabelTitleWikiBook" /> 
     <item 
      android:id="@+id/nav_forum" 
      android:title="@string/LabelTitleForum" 
      /> 
     <item 
      android:id="@+id/nav_history" 
      android:title="@string/LabelHistory" 
      /> 
     <item 
      android:id="@+id/nav_favs" 
      android:title="@string/LabelFavourites" 
      /> 
    </group> 

    <item android:title="@string/LabelTitleSupportPages"> 
     <menu> 
      <item 
       android:id="@+id/nav_options" 
       android:title="@string/LabelTitleSettings" /> 
      <item 
       android:id="@+id/nav_qa" 
       android:title="@string/LabelTitleAbout" /> 
      <item 
       android:id="@+id/nav_facebook" 
       android:title="@string/LabelTitleFB" /> 
     </menu> 
    </item> 

</menu> 
+0

過去のメニューxmlはこちら –

+0

私が知る限りmenu.xmlは使用していません。 – user1293618

+0

これはあなたに役立つと思います: [link](http://stackoverflow.com/questions/30886453/change-the-color-of-a-checked-menu-item-in-a-navigation-drawer) –

答えて

3

試してみてください。

<item name="android:textColorSecondary">#eeeeee</item> 

編集:

は交換してください:

<style name="AppTheme.NoActionBar" parent="@style/Theme.AppCompat"> 
     <item name="android:windowBackground">@color/darkblue</item> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 

<style name="AppTheme.NoActionBar" parent="@style/Theme.AppCompat"> 
     <item name="android:windowBackground">@color/darkblue</item> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 

     <item name="android:textColorSecondary">#eeeeee</item> 
    </style> 

編集2:

<style name="AppTheme.NoActionBar" parent="@style/Theme.AppCompat"> 
      <item name="android:windowBackground">@color/darkblue</item> 
      <item name="windowActionBar">false</item> 
      <item name="windowNoTitle">true</item> 

      // change header color  
      <item name="android:textColorSecondary">#eeeeee</item> 
      // change separator color 
      <item name="android:listDivider">#ff000000</item> 
     </style> 
+0

どこにこれを置くのですか? – user1293618

+0

あなたのクラスの親テーマの中に入れてください。例えば 'について<スタイル名= "AppTheme" 親= "Theme.AppCompat.Light.DarkActionBarは"> <=項目名 "アンドロイド:textColorSecondary">#のeeeeee ' –

+0

さもないと、あなたの活動のテーマを投稿します。 –

0

あなたの引き出しのアイテムのカスタムレイアウトを作成し、NavigationViewにカスタムレイアウトを含めることができます。これ

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


     <include 
      layout="@layout/sidedrawer" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" /> 

    </android.support.design.widget.NavigationView> 
と同様に、これと

sidedrawerはあなたのカスタムレイアウトです。あなたが望む任意のスタイルや色を提供することができます。それがあなたに役立つことを願って

関連する問題