1
嗯,我知道,这可以在XML这样有没有办法从android设置背景:以编程方式绘制?
android:background="@android:drawable/editbox_dropdown_dark_frame"
上面这条线是从我的脑海里,因此它可以有一定的错误来完成,但基本上是这样的。现在我怎么能做同样的事情,但编程?
感谢
嗯,我知道,这可以在XML这样有没有办法从android设置背景:以编程方式绘制?
android:background="@android:drawable/editbox_dropdown_dark_frame"
上面这条线是从我的脑海里,因此它可以有一定的错误来完成,但基本上是这样的。现在我怎么能做同样的事情,但编程?
感谢
你可以做这样的(从View子类):
setBackgroundResource(android.R.drawable.editbox_dropdown_dark_frame);
如果你有到视图的引用(比如,从findViewById
),你可以做同样的事情:
View v = . . .;
v.setBackgroundResource(android.R.drawable.editbox_dropdown_dark_frame);
如果你喜欢,你可以检索Drawable
本身直接:
Drawable d = getResources().getDrawable(
android.R.drawable.editbox_dropdown_dark_frame);
<TextView
android:id="@+id/background_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
TextView toChange = (TextView) this.findViewById(R.id.background_tv);
toChange.setBackgroundResource(android.R.drawable.editbox_dropdown_dark_frame);