1

私はこれがこのようにxmlで行うことができることを知っています

android:background="@android:drawable/editbox_dropdown_dark_frame"

上記のこの行は私の考えによるものなので、エラーが発生する可能性がありますが、基本的にはそのようになっています。さて、どうすれば同じことをプログラムで行うことができますか?

ありがとう

4

2 に答える 2

4

(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);
于 2012-10-25T22:34:59.803 に答える
1
<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);
于 2012-10-25T22:35:15.593 に答える