首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android -如何在Android上设置以✔为文本的按钮上的文本颜色

Android -如何在Android上设置以✔为文本的按钮上的文本颜色
EN

Stack Overflow用户
提问于 2016-05-07 11:34:46
回答 3查看 738关注 0票数 2

论Android M

代码语言:javascript
复制
button.setText("✔");
button.setTextColor(Color.WHITE);

不知道为什么吗?

我怎样才能得到✔白色的颜色?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-05-07 12:04:30

您也可以使用unicode作为勾标,尝试在字符串中使用✓并将其设置为textview。

票数 0
EN

Stack Overflow用户

发布于 2016-05-07 11:59:02

试着这样做,

在xml文件中,

代码语言:javascript
复制
<?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 >

现在,在java文件中添加以下代码

代码语言:javascript
复制
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);
    }
}
票数 1
EN

Stack Overflow用户

发布于 2016-05-07 11:48:13

实际上,您可以添加可绘制的视图。就像xml中的那样:

代码语言:javascript
复制
<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" />

在您的代码中,您也可以这样做:

代码语言:javascript
复制
Drawable top = getResources().getDrawable(R.drawable.image);
//placement is like that : left, top, right, bottom
button.setCompoundDrawablesWithIntrinsicBounds(null, top , null, null);

我采用这样的解决方案:How to set property “android:drawableTop” of a button at runtime

此外,您还可以这样更改drawable的tint值:

代码语言:javascript
复制
public static Drawable setTint(Drawable d, int color) {
    Drawable wrappedDrawable = DrawableCompat.wrap(d);
    DrawableCompat.setTint(wrappedDrawable, color);
    return wrappedDrawable;
}

此解决方案基于:change color of drawable

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37088025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档