作者:ZYL-120501 | 来源:互联网 | 2023-02-01 14:53
我试图动态创建textview.我想将drawable设置为textview`
TextView tab = new TextView(getContext());
tab.setText(title);
tab.setSingleLine();
tab.setGravity(Gravity.CENTER);
int padding = getResources().getDimensionPixelOffset(R.dimen.offset);
tab.setPadding(0,0,padding,0);
if(typeface!= null){
tab.setTypeface(typeface);
}
tab.setCompoundDrawables(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp),null,null,null);
"但我无法实现它.你们中的任何人都可以帮助我吗?
1> IntelliJ Ami..:
使用setCompoundDrawablesWithIntrinsicBounds
将Drawables(如果有)设置为显示在文本的左侧,上方,右侧和下方.如果你不想在那里使用Drawable,请使用null.Drawables的界限将设置为其内在界限.
setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp),null,null,null);
要么
setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp),0,0,0);