Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将文本和图像放入按钮中,并且需要动态进行。我知道如何在 xml 代码中执行此操作,但我无法将其转换为 java 代码。
尝试这个,
Button b=new Button(this); b.setCompoundDrawablePadding(10); b.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);
试试这个代码:
button.setCompoundDrawables(Drawable left,Drawable top,Drawable right,Drawable bottom);