论Android M
button.setText("✔");
button.setTextColor(Color.WHITE);不知道为什么吗?
我怎样才能得到✔白色的颜色?
发布于 2016-05-07 12:04:30
您也可以使用unicode作为勾标,尝试在字符串中使用✓并将其设置为textview。
发布于 2016-05-07 11:59:02
试着这样做,
在xml文件中,
<?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文件中添加以下代码
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);
}
}发布于 2016-05-07 11:48:13
实际上,您可以添加可绘制的视图。就像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" />在您的代码中,您也可以这样做:
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值:
public static Drawable setTint(Drawable d, int color) {
Drawable wrappedDrawable = DrawableCompat.wrap(d);
DrawableCompat.setTint(wrappedDrawable, color);
return wrappedDrawable;
}此解决方案基于:change color of drawable
https://stackoverflow.com/questions/37088025
复制相似问题