我有一个带有TextView和ImageView的AppWidget布局。
Lint总是告诉我要用复合TextView替换它。
问题是,我如何在RemoteViews中调用setCompoundDrawables呢?这可行吗?
谢谢。
我有一个带有TextView和ImageView的AppWidget布局。
Lint总是告诉我要用复合TextView替换它。
问题是,我如何在RemoteViews中调用setCompoundDrawables呢?这可行吗?
谢谢。
当您使用setCompoundDrawables时,需要编写类似以下的代码:
Drawable img;
Resources res = getResources();
img = res.getDrawable(R.drawable.btn_img);
//You need to setBounds before setCompoundDrawables , or it couldn't display
img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight());
btn.setCompoundDrawables(img_off, null, null, null);
所以你必须有调用getResources()的方法! 你可以将Activity上下文作为参数传递,以使用getResources()和findViewById。
使用 setTextViewCompoundDrawables
contentiew.setTextViewCompoundDrawables(R.id.setting_btn, 0, R.mipmap.ic_gray_setting,0,0);