2016-11-28 189 views
0

我试图在几种布局中使用圆形形状,但由于某些原因,即使角落是圆形的,在背景中也有不圆角的角落。 有人知道为什么吗?Android圆形转角不圆

代码:

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(的对话框):

<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(所述的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> 

是这样的:

Dialog image

EditText image

谢谢

+0

我的坏...它刚刚在格式化中丢失了 – henengel

+0

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

+0

尝试angrytools.com –

回答

0

尝试

<?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> 
+0

我需要一个圆角矩形,而不是椭圆形 – henengel

+0

@ManikandanK检查它。除了笔触颜色不同外,看起来与问题相同。 – henengel

+0

@ManikandanK我做到了这一点,它确实工作,但通常情况下,我仍然有问题。 我也使用EditText上的形状,并具有相同的问题。由于我使用setBackgroundDrawable形状,我不能用它来设置背景透明度。任何想法? - – henengel

0

我有修改了你的一些代码。试试 我刚刚在代码中添加了形状标签。它会为你工作。

<?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> 

为编辑文本使用 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> 

而在你的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> 
+0

不幸的是,它没有奏效。仍然看起来一样。 – henengel

+0

@henengel add dialog.getWindow()。setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT))。 –

+0

做到了这一点,并确实解决了对话问题。仍然有edittext问题 – henengel

0

没有什么错你的背景和它的绘制。这里的问题是对话框主题。

尝试将对话背景设置为透明,如建议here

如果这将不利于试图改变主题,以自定义的,如建议here

+0

这可能会修复对话框问题,但不是EditText之一。 dialog.getWindow()。setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)) 也修复了对话框问题。 – henengel

2

在额外的角来,因为对话的。您的布局在活动和碎片的情况下完美运行。对于对话刚刚成立

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

,或者如果您发现有任何其他的方法来设置对话框的背景为透明地使用那一个。

+0

这确实与对话框一起工作。 我也使用EditText上的形状,并具有相同的问题。 由于我正在使用setBackgroundDrawable形状,我不能用它来设置背景透明度。 有什么想法? – henengel

+0

编辑文本中editText图像 – henengel

+0

更新的问题在edittext图像中得到的那样? –