1

Well I know that this can be done in xml this way

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

this line above is from my mind so it can have some errors, but basically is that way. Now how can I do the same thing but programatically?

Thanks

2 Answers 2

4

You can do it like this (from a View subclass):

setBackgroundResource(android.R.drawable.editbox_dropdown_dark_frame);

If you have a reference to the view (say, from findViewById), you can do the same thing:

View v = . . .;
v.setBackgroundResource(android.R.drawable.editbox_dropdown_dark_frame);

If you like, you can retrieve the Drawable itself directly:

Drawable d = getResources().getDrawable(
    android.R.drawable.editbox_dropdown_dark_frame);
Sign up to request clarification or add additional context in comments.

Comments

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.