简体   繁体   中英

Android round shape corners not round

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

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.

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>

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM