gpt4 book ai didi

android - 无法动态设置可绘制的textview

转载 作者:太空狗 更新时间:2023-10-29 15:50:32 32 4
gpt4 key购买 nike

我正在尝试动态创建 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);

`但我无法实现它。你们谁能帮帮我。

最佳答案

使用 setCompoundDrawablesWithIntrinsicBounds

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use null if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

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);

关于android - 无法动态设置可绘制的textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44496312/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com