我知道这可以用这种方式在 xml 中完成
android:background="@android:drawable/editbox_dropdown_dark_frame"
上面这行是我的想法所以它可能有一些错误,但基本上就是这样。现在我怎样才能以编程方式做同样的事情呢?
谢谢
最佳答案
您可以这样做(从 View 子类):
setBackgroundResource(android.R.drawable.editbox_dropdown_dark_frame);
如果您有对 View 的引用(例如,来自 findViewById
),您可以做同样的事情:
View v = . . .;
v.setBackgroundResource(android.R.drawable.editbox_dropdown_dark_frame);
如果愿意,您可以直接检索 Drawable
本身:
Drawable d = getResources().getDrawable(
android.R.drawable.editbox_dropdown_dark_frame);
关于java - 有没有办法从android :drawable programatically?设置背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13078324/