2

On Android M

button.setText("✔");
button.setTextColor(Color.WHITE);

Does not work any idea why?

How can i get the ✔ white colored?

Kristiyan Petrov
  • 215
  • 3
  • 10

3 Answers3

1

try doing this way,

in your xml file,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@mipmap/ic_launcher"
        android:hint="hii" />
</LinearLayout >

Now, in your java file add this code like

public class SixthActivity extends AppCompatActivity {

    Button btn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first_activity);
        btn = (Button) findViewById(R.id.btn);

        btn.setText("");
        btn.setBackgroundColor(getResources().getColor(R.color.white));
        btn.setBackgroundResource(R.mipmap.ic_launcher);
    }
}
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
0

Actually you can add drawables to view. Like that in xml :

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Load More"
    android:id="@+id/loadMore"
    android:drawableLeft="@drawable/your_marked_icon"
    android:drawableRight="@drawable/another_icon_if_need"
    style="?android:attr/borderlessButtonStyle"
    android:layout_centerHorizontal="true" />

Also in your code you can do like that :

Drawable top = getResources().getDrawable(R.drawable.image);
//placement is like that : left, top, right, bottom
button.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);

I take this solution in : How to set property “android:drawableTop” of a button at runtime

Also you can change drawable's tint value like that:

public static Drawable setTint(Drawable d, int color) {
    Drawable wrappedDrawable = DrawableCompat.wrap(d);
    DrawableCompat.setTint(wrappedDrawable, color);
    return wrappedDrawable;
}

this solution based on : change color of drawable

Community
  • 1
  • 1
Yasin Kaçmaz
  • 6,573
  • 5
  • 40
  • 58
0

You can use unicode also for tick mark,Try to use &#x2713; with string and set it to your textview.

Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96