我遇到某些文字观点的问题,这些观点固执地不会改变颜色。我不确定为什么它不起作用。
我的颜色是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>
我尝试过对layout.xml文件中的颜色进行硬编码以及动态设置颜色:
descriptionHeader.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
和
android:textColor="@color/colorPrimaryDark"
在图像中注意带有棕色色调的文本,即所需的颜色。 “描述”,它的正文和“说明”决定只是一个浅灰色
下面是我的布局代码:
<?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 :(得分:0)
弄清楚发生了什么:
在带有颜色问题的文字视图中,我正在使用
android:hint="@string/brew_method_description
而不是
android:text="@string/brew_method_description
切换设置实际文本启用了颜色更改。