0

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/

Johnny Wong
  • 105
  • 1
  • 2
  • 9

2 Answers2

1

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.

Community
  • 1
  • 1
Rick
  • 3,943
  • 6
  • 33
  • 45
  • Thank you for your comment. I sorry that I may confuse you from the code above. I actually want to make the shape like this [link] (http://openclipart.org/detail/27891/set-of-eight-rounded-shapes-by-rg1024-27891). I end up get the correct shape but there is a black color outside the corner. Hope you get what I mean. Thanks. – Johnny Wong Feb 08 '14 at 16:13
0

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

mishasrb
  • 49
  • 7
  • Yes, I need to create a border align with the rounded corner. But there is a black color outside the corner now. I want to make it transparent. – Johnny Wong Feb 09 '14 at 00:18
  • Ok, it would be much easier if you post the code of your layout xml but I think you should put your LinearLayout in another layout that has the same dimensions but not the rounded corner and than set the color of this container layout to transparent or even better set the same color as the background is. – mishasrb Feb 09 '14 at 10:58
  • I have edit my post and the code attached. Thank you for your help!! – Johnny Wong Feb 10 '14 at 01:36
  • I think that the problem is with transparent background of the container linearlayout. If you know what color should be in the background put it instead of @android:color/transparent. If you don't, try removing container layout or programmatically in the code set it's color when and where you use it. – mishasrb Feb 10 '14 at 11:47
  • Ok, I removed the container layout and it got a same result. I am using setContentView method to open this layout. Am I correct to call this layout? Thank you for your patient to answer me a question. I am so new for Android Dev.> – Johnny Wong Feb 10 '14 at 13:02
  • The dark color is the color of the Android background. Put back the container and set it's background color to color that you want. – mishasrb Feb 11 '14 at 10:11
  • So, can the color of the container set to transparent? It is so wired to hv a dark color arround the alert dialog – Johnny Wong Feb 11 '14 at 14:48
  • You can set it to transparent but if you use ths component somewhere where you don't have and other view beneath it it while be dark beacase than it will use the default Android color which is dark. – mishasrb Feb 14 '14 at 09:16