0

I'm trying to use a rounded shape in several layouts, but from some reason even though the corners are rounded, in the background there are corners that are not rounded. Does anybody have an idea why?

Code:

dialog_background:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="@color/jobim_white" ></solid>

<stroke
    android:width="1dp"
    android:color="@color/colorPrimary" ></stroke>

<corners android:radius="8dp"></corners>

</shape>

search_edittext_shape:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp" >

<solid android:color="#FFFFFF" />

<corners
    android:bottomLeftRadius="8dp"
    android:bottomRightRadius="8dp"
    android:topLeftRadius="8dp"
    android:topRightRadius="8dp" />

</shape>

RelativeLayout (of the dialog):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dialog_background" >

LinearLayout (of the EditText):

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:background="#ECECEC">

    <EditText
        android:id="@+id/searchTypeEdtTxt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableRight="@drawable/ic_search"
        android:drawableTint="#D0D0D0"
        android:background="@drawable/search_edittext_shape"
        android:hint="@string/search"
        android:textColorHint="#ECECEC"
        android:elevation="3dp"
        android:textCursorDrawable="@drawable/cursor_color" />

</LinearLayout>

Looks like this:

Dialog image

EditText image

Thank you

Roy Hen Engel
  • 625
  • 1
  • 7
  • 21

4 Answers4

4

In extra corners are coming because of dialog. Your layout works perfectly in case of activities and fragments. For dialogs just set

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 

or if you found any other way to set dialog background as transparent use that one.

Prashanth Debbadwar
  • 1,047
  • 18
  • 33
0

try it

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >

        <solid android:color="#FFFFFF" />
        <corners android:radius="3dip" />
        <stroke
            android:width="1dp"
            android:color="#ADADAD" />

    </shape>
Manikandan K
  • 911
  • 9
  • 21
  • I need a rounded rectangle, not oval – Roy Hen Engel Nov 28 '16 at 10:03
  • @ManikandanK Checked it. Except for the stroke color being different lt look the same, with the problem. – Roy Hen Engel Nov 28 '16 at 10:16
  • @ManikandanK I did that and it did work but generally, I still have the problem. I'm also using the shape on an EditText and have the same problem. Since I'm using setBackgroundDrawable to the shape, I can't use this to set the background transparency. Any idea? – – Roy Hen Engel Nov 28 '16 at 10:26
0

I have modified some of your code. try that I have just added shape tag in your code. It will work for you.

<?xml version="1.0" encoding="utf-8"?>
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">

        <solid android:color="@color/jobim_white" ></solid>

       <stroke
           android:width="1dp"
           android:color="@color/colorPrimary" ></stroke>

       <corners android:radius="8dp"></corners>
    </shape>

for edit text use rounded_corner.xml

<?xml version="1.0" encoding="utf-8"?>
    <shape
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle">

      <!-- view background color -->
      <solid
          android:color="@color/colorPrimary" >
      </solid>

        <!-- If you want to add some padding -->
     <padding
          android:left="4dp"
          android:top="4dp"
          android:right="4dp"
          android:bottom="4dp"    >
     </padding>

        <!-- Here is the corner radius -->
     <corners
         android:radius="20dp"   >
     </corners>
</shape>

And in your LinearLayout

  <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:background="#ECECEC">

            <EditText
                 android:id="@+id/searchTypeEdtTxt"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:drawableRight="@drawable/ic_action_search"
                 android:drawableTint="#D0D0D0"
                 android:background="@drawable/rounded_corner"
                 android:hint="@string/search"
                 android:textColorHint="#ECECEC"
                 android:textCursorDrawable="@color/black" />
  </LinearLayout>
Deepak Sachdeva
  • 950
  • 8
  • 16
0

There is nothing wrong with your background and it's drawable. The problem here is the dialog theme.

Try to set dialog background to transparent, as suggested here.

If this won't help try changing the theme to custom one, as suggested here

Community
  • 1
  • 1
R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
  • This maybe fixes the dialog problem, but not the EditText one. dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)) also fixed the dialog problem. – Roy Hen Engel Nov 28 '16 at 10:34