Johnny Wong
Johnny Wong

Reputation: 105

Android: Applying rounded shape to a linear layout

I am gonna to create the a alert dialog box in android with rounded shape. I follow many threads in this site. Create a shape.xml and place it drawables

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
 android:shape="rectangle"> 
 <stroke android:width="5dp" android:color="#FF0000" />
<corners android:bottomRightRadius="20dp" android:bottomLeftRadius="20dp" 
 android:topLeftRadius="20dp" android:topRightRadius="20dp"/> <solid android:color="#FFFF00"/>

And apply the above shape to the linearlayout. layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:color/transparent" >

<LinearLayout android:layout_width="200dip"
    android:layout_height="60dip"
    android:orientation="vertical"
    android:background="@drawable/shape">

</LinearLayout>

However, there is still have a rectangle border and back color outside the dialog box. That is not what I want. I have search for a long time I dont know how to fix it. I aimed to make it transparent outside the corner of the dialog box layout. Thank you so much!

Screen Shot: http://postimg.org/image/3xbnmquyt/

Upvotes: 0

Views: 2557

Answers (2)

mishasrb
mishasrb

Reputation: 49

Remove the stroke tag because it is used for creating the border. Also you shouldn't use gradient and solid together because they exclude one another.

http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

Upvotes: 0

Rick
Rick

Reputation: 4013

For the shape you want I found the default one on Android Studio, this:

android:background="@drawable/abc_menu_dropdown_panel_holo_light"

Apply it to your LinearLayout, It is exatcly what you're talikng about and you don't need to create other xml files in the drawables. To see how It looks like see my answer here: Android View shadow

Hope I helped you.

Upvotes: 1

Related Questions