Stanly T
Stanly T

Reputation: 1054

Why I can't change the Button's textColor

I try to change the button textColor's parameter, but all my efforts below are in vain.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:background="@color/colorPrimaryDark"
    android:orientation="vertical"
    android:tag="fragment_register">
    <TextView
        android:id="@+id/tv_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:text="@string/title"
        android:textColor="@android:color/white"
        android:textSize="20sp"/>
    <EditText
        android:id="@+id/et_first_password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:background="#3f3f3f"
        android:padding="10dp"
        android:ems="17"
        android:textColor="@color/colorWhite"
        android:hint="@string/hint_enter_password"
        android:textColorHint="#696969"/>
    <EditText
        android:id="@+id/et_first_pass_again"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:background="#3f3f3f"
        android:padding="10dp"
        android:ems="17"
        android:textColor="@color/colorWhite"
        android:hint="@string/hint_reenter_password"
        android:textColorHint="#696969"/>
    <Button
        android:id="@+id/reg_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_margin="20dp"
        android:background="#494949"
        android:text="@string/btn_title_reg"
        android:textColor="@color/colorWhite"/>
</LinearLayout>

The color has changed only in Preview Design Layout window, but it doesn't work in launched app. button.setTextColor(...); It doesn't work as well

Can anybody help me please?

Upvotes: 0

Views: 82

Answers (3)

akansha06 jain
akansha06 jain

Reputation: 46

Try this

button.setTextColor(Color.parseColor("#000fff"));

or you can use

button.setTextColor(getResources().getColor(R.color.colorPrimary));

Upvotes: 0

Moshe Edri
Moshe Edri

Reputation: 244

Try clear your project before building it

Build -> Clean Project or Build -> Rebuild Project

Sometimes android catch some of the previous build to save build time.

Upvotes: 0

AskNilesh
AskNilesh

Reputation: 69671

you should use

android:textColor="#FFFFFF"

instead of

tools:textColor="@android:color/white"

or try to set programatically like this

button.setTextColor(ContextCompat.getColor(YourActivity.this,R.color.colorBlack));

Upvotes: 1

Related Questions