2017-04-05 5 views
1

私は頑強に色を変えない特定のテキストビューに問題があります。なぜそれが動作していないのか分かりません。TextViewのテキストの色が変わらないのはなぜですか?

私は両方layout.xmlファイル内の色をハードコーディングするだけでなく、動的に色を設定しようとしましたresource/colors.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="colorPrimary">#FDCDB2</color> 
    <color name="colorPrimaryDark">#E2896B</color> 
    <color name="colorAccent">#FF4081</color> 
    <color name="mainBackground">#F6F5F5</color> 
</resources> 

に自分の色を持っている:

descriptionHeader.setTextColor(getResources().getColor(R.color.colorPrimaryDark)); 

android:textColor="@color/colorPrimaryDark" 

画像には、茶色の色調のテキスト、つまり希望の色が表示されます。 「説明」、その身体、および「取扱説明書は、」すぐ下

enter image description here

ライトグレーにすることを決定したレイアウトのための私のコードです:

何が起こっていたか考え出し
<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical"> 

    <!--make whole layout scrollable--> 
    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="?attr/actionBarSize" 
     android:orientation="vertical"> 

     <!--nested view can only have one child--> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:textColor="@color/colorPrimary" 
      > 

      <!-- main image of the brew method--> 
      <ImageView 
       android:id="@+id/topImageIV" 
       android:layout_width="300dp" 
       android:layout_height="300dp" 
       android:layout_gravity="center|top" 
       android:background="@color/colorPrimary" 
       android:focusableInTouchMode="true" /> 

      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <!--layout for the brew parameteres--> 
       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@drawable/brew_method_parameters" 
        android:orientation="horizontal" 
        android:padding="8dp" 
        android:weightSum="3"> 

        <!--layout for the weight--> 
        <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:layout_gravity="center_horizontal" 
         android:layout_weight="1" 
         android:orientation="vertical"> 

         <!--top row of the weight includes image--> 
         <LinearLayout 
          android:layout_width="match_parent" 
          android:layout_height="30dp" 
          android:gravity="center" 
          android:orientation="horizontal"> 

          <!--weight image icon--> 
          <ImageView 
           android:id="@+id/weight_icon_IV" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_gravity="center" 
           android:focusableInTouchMode="true" 
           android:src="@drawable/ic_weight" /> 

          <!--weight parameter set dynamically--> 
          <TextView 
           android:id="@+id/TV_servingDose" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_gravity="center" 
           android:gravity="center" 
           android:hint="16 g" 
           android:textColor="@color/colorPrimaryDark" /> 
         </LinearLayout> 

         <!--serving size set dynamically--> 
         <TextView 
          android:id="@+id/TV_servingNumber" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:gravity="center" 
          android:hint="1 Serving" 
          android:paddingLeft="12dp" 
          android:textColor="@color/colorPrimaryDark" /> 
        </LinearLayout> 

        <!--layout for time requirement--> 
        <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:layout_gravity="center_horizontal" 
         android:layout_weight="1" 
         android:orientation="vertical"> 

         <!--top row of time requirement--> 
         <LinearLayout 
          android:layout_width="match_parent" 
          android:layout_height="30dp" 
          android:gravity="center" 
          android:orientation="horizontal"> 

          <!--time icon--> 
          <ImageView 
           android:id="@+id/timer_icon_IV" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_gravity="center" 
           android:focusableInTouchMode="true" 
           android:src="@drawable/ic_clock" /> 

          <!--brew time set dynamically--> 
          <TextView 
           android:id="@+id/TV_timer" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:gravity="center" 
           android:hint="4:00" 
           android:textColor="@color/colorPrimaryDark" /> 
         </LinearLayout> 

         <!--brew time label--> 
         <TextView 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:gravity="center" 
          android:paddingLeft="15dp" 
          android:text="Brew Time" 
          android:textColor="@color/colorPrimaryDark" /> 

        </LinearLayout> 
        <!--layout for grind size--> 
        <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:layout_gravity="center_horizontal" 
         android:layout_weight="1" 
         android:orientation="vertical"> 

         <!--top row of grind size includes image--> 
         <LinearLayout 
          android:layout_width="match_parent" 
          android:layout_height="30dp" 
          android:gravity="center" 
          android:orientation="horizontal"> 

          <!--icon for grind--> 
          <ImageView 
           android:id="@+id/grind_icon_IV" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_gravity="center" 
           android:focusableInTouchMode="true" 
           android:src="@drawable/ic_grinder" /> 

          <!--grind description set dynamically--> 
          <TextView 
           android:id="@+id/TV_grindSetting" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:gravity="center" 
           android:hint="@string/grind_size_coarse" 
           android:textColor="@color/colorPrimaryDark" /> 
         </LinearLayout> 
         <!--grind setting description--> 
         <TextView 
          android:layout_width="match_parent" 
          android:layout_height="0dp" 
          android:layout_weight="1" 
          android:gravity="center" 
          android:paddingLeft="12dp" 
          android:text="@string/grind_setting" 
          android:textColor="@color/colorPrimaryDark" /> 
        </LinearLayout> 
       </LinearLayout> 
      </android.support.v7.widget.CardView> 

      <!--description of brewmethod layout--> 
      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="8dp" 
       android:orientation="vertical" 
       app:cardCornerRadius="2dp"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@color/mainBackground" 
        android:orientation="vertical"> 

        <!--description label--> 
        <TextView 
         android:id="@+id/description_header_TV" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:hint="@string/brew_method_description" 
         android:paddingStart="16dp" 
         android:textColor="@color/colorPrimaryDark" 
         android:textSize="24sp" /> 

        <!--description text--> 
        <TextView 
         android:id="@+id/brew_method_description_TV" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:hint="@string/bio_aeropress" 
         android:paddingBottom="8dp" 
         android:paddingRight="16dp" 
         android:paddingStart="16dp" 
         android:textColor="@color/colorPrimaryDark" /> 
       </LinearLayout> 
      </android.support.v7.widget.CardView> 

      <!--instructions label--> 
      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="8dp" 
       android:orientation="vertical" 
       app:cardCornerRadius="2dp"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@color/mainBackground" 
        android:orientation="vertical"> 

        <TextView 
         android:id="@+id/brew_method_instructions_title_TV" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:backgroundTint="@color/colorPrimaryDark" 
         android:hint="@string/brew_method_instructions" 
         android:paddingStart="16dp" 
         android:textSize="24sp" /> 

        <!--instuctions recyclerview. set using InstructionListAdapter--> 
        <android.support.v7.widget.RecyclerView 
         android:id="@+id/rvInstructions" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:minHeight="0dp"> 

        </android.support.v7.widget.RecyclerView> 
       </LinearLayout> 
      </android.support.v7.widget.CardView> 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 


    <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" 
      app:titleTextColor="@color/colorPrimaryDark" /> 

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

    <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" 
     android:backgroundTint="@color/colorPrimaryDark" 
     app:srcCompat="@android:drawable/ic_lock_idle_alarm" /> 


</android.support.design.widget.CoordinatorLayout> 
+0

**あなたの** android:theme **に多少の影響があります。 – statosdotcom

+0

@statosdotcom上記の編集で 'values/styles.xml'を追加しました。スタイルはグレーの陰影を参照しません。 –

+0

ニース、ありがとう。そして、あなたのマニフェストは** AppTheme **を指していますよね? OK。それから、必要なものを得るためにあなたのテーマを無効にする時です。あなたのTextViewのテーマを作成します。これは、あなたのXML上で、これが目的の色を得ることを禁止する何かがあると思われるからです。おそらくあなたのテーマをハードコーディングしてあなたの道を見つけるでしょう。 (長生きの恋人) – statosdotcom

答えて

0

:色の問題と私のテキストビューで

、私が使っていた

android:hint="@string/brew_method_description

代わりに、実際のテキストを設定するスイッチング

android:text="@string/brew_method_description

は、色の変化を可能にしました。

関連する問題