NSouth
NSouth

Reputation: 5276

How do I use the default android Button drawable as the background of another view?

I have a LinearLayout that I would like to make look like a button. It was suggested that I apply the android:drawable/btn_default as the background to my View, but this makes the View look like an Android 2.3 button. I'd like it to simply look like the other buttons on the screen. What am I missing?

My XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linlay_add_category_area_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="@android:drawable/btn_default"
    android:orientation="horizontal"
    android:padding="13dp" >

Upvotes: 2

Views: 640

Answers (2)

fikr4n
fikr4n

Reputation: 3430

Have you tried to use Button's style like this.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/buttonStyle"
    android:id="@+id/linlay_add_category_area_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:orientation="horizontal"
    android:padding="13dp">
...
</LinearLayout>

Upvotes: 2

Bartek Lipinski
Bartek Lipinski

Reputation: 31468

I'm not sure if you can specify somehow from which sdk you would like android to pick up those resources.

What you can do instead, is to copy proper resources from the SDK directories (on your computer) to your project directories. And use them just like you would with your own resources.

You can find those resources in:

[SDK]/platforms/android-[VERSION]/data/res/

just remember to copy the selector file located here:

[SDK]/platforms/android-[VERSION]/data/res/drawable/btn_default.xml

and all the necessary (necessary = used in selector file) resources from other drawable directories (drawable-ldpi, drawable-mdpi, drawable-xdpi etc.)

Upvotes: 0

Related Questions