问题
I am implement floating label as per material design . Now i want to change the color of few elements like change the color of default hint (Email id which black right now) and line below it .
I have gone through similar question like these but couldn't solve my problem .
<resources>
<style name="AppTheme" parent="AppTheme.BaseTheme"></style>
<style name="AppTheme.BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="Signin_EditText" parent="TextAppearance.AppCompat">
<item name="colorAccent">@color/white</item>
<item name="colorPrimary">@color/white</item>
<item name="android:editTextColor">@color/white</item>
<item name="colorControlActivated">@color/white</item>
<item name="colorControlHighlight">@color/white</item>
</style>
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input_layout_email"
android:layout_width="match_parent"
app:hintTextAppearance="@style/Signin_EditText"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edittext_emailid"
android:layout_width="match_parent"
android:textSize="14sp"
android:minHeight="35dp"
android:layout_height="wrap_content"
android:textColorHint="@color/white"
android:inputType="textEmailAddress"
android:textColor="@color/white"
android:hint="@string/emailid"/>
</android.support.design.widget.TextInputLayout>
回答1:
Try this.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorControlNormal">@color/primary_light</item>
<item name="colorControlHighlight">@color/primary_light</item>
<item name="colorControlActivated">@color/primary_light</item>
<item name="colorAccent">@color/primary_light</item>
<item name="colorPrimary">@color/primary_light</item>
<item name="colorPrimaryDark">@color/secondary_dark</item>
</style>
回答2:
Change your colorAccent to the required color.
回答3:
You can't Override the Colors colorAccent, colorPrimary, colorPrimaryDark or any other colors which are used for Theme by AppCompact. You can only Define them in Application Theme which you will in use in Manifest file.
If you want Customize your theme colors, you have to define them in BaseTheme which you are using in Manifest file <application... tag as below
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorControlNormal">@color/primary_light</item>
<item name="colorControlHighlight">@color/primary_light</item>
<item name="colorControlActivated">@color/primary_light</item>
<item name="colorAccent">@color/primary_light</item>
<item name="colorPrimary">@color/primary_light</item>
<item name="colorPrimaryDark">@color/secondary_dark</item>
</style>
Manifest file:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
...
</application>
来源:https://stackoverflow.com/questions/32584788/how-to-change-the-floating-label-color-of-textinputlayout