我正在动态创建按钮。首先使用XML对其进行样式设置,现在我正在尝试使用下面的XML以编程方式创建它们。
<Button
android:id="@+id/buttonIdDoesntMatter"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="buttonName"
android:drawableLeft="@drawable/imageWillChange"
android:onClick="listener"
android:layout_width="fill_parent">
</Button>
这是我目前的进展。除了drawable之外,我什么都可以做。
linear = (LinearLayout) findViewById(R.id.LinearView);
Button button = new Button(this);
button.setText("Button");
button.setOnClickListener(listener);
button.setLayoutParams(
new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT
)
);
linear.addView(button);
drawableLeft
在列表视图中显示文件夹。我尝试了你们在这里的建议,在单击没有读取权限的文件夹时设置“禁止图标”,它有效。但是,当你更改文件夹并重新加载适配器时,禁止图标仍然存在(即drawableLeft
没有重新绘制)。你们知道如何将notifyDataSetChanged
应用于drawableLeft
,而不需要进行循环吗?谢谢! - Luis A. FloritListview
项的问题——这与此问题或答案没有真正的关系。我建议你发一个问题而不是评论。 - TiggersetCompoundDrawablesWithIntrinsicBounds (0, 0, R.drawable.money, 0)
将不起作用。如果我在onCreate()
中设置原始图标,则更改会生效。这可能与API 19有关吗? - injecteerdrawableStart
和drawableEnd
怎么样? - MHSaffari