如何使用顶角圆形和底部矩形创建递观

  • 本文关键字:底部 创建 递观 何使用 android
  • 更新时间 :
  • 英文 :


我在可绘制的文件夹中有一个简单的背景,只是我在deDittext上使用的边框:

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners
        android:radius="2dp"
        />
    <solid android:color="#ffffff"
        />
    <stroke
        android:width="1dip"
        android:color="#000" />
</shape>

,但我想实现这一目标。边缘的顶部和底部矩形!我遇到了麻烦,然后做这个

创建一个 Drawable shape xml文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <stroke
        android:width="1dip"
        android:color="@color/colorAccent"/>
    <corners android:radius="10dp"
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="0dp"/>
</shape>

在您的dittext背景中设置 drawable

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Your Text"
    android:padding="@dimen/dimen10"
    android:background="@drawable/testing"/>

创建round_shape.xml

 <?xml version="1.0" encoding="utf-8"?>
            <shape xmlns:android="http://schemas.android.com/apk/res/android">
            
                <solid android:color="@color/white"/>
                <corners android:bottomRightRadius="0dp"
                    android:bottomLeftRadius="0dp"
                    android:topLeftRadius="20dp"
                    android:topRightRadius="20dp"/>
            
            </shape>

设置可绘制的您编辑文本背景

<EditText
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:background="@drawable/round_shape"/>

请为我尝试这项工作

<solid android:color="#ffffff" />
<stroke
    android:width="1dp"
    android:color="#000" />
<corners
    android:bottomLeftRadius="0dp"
    android:bottomRightRadius="0dp"
    android:topLeftRadius="25dp"
    android:topRightRadius="25dp" />

请检查并更改半径。

在这里创建editox_custom_top_radius.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!--Here Corner use for give curve to your edit text-->
    <corners android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
    <!--stroke is use to apply border on edit text-->
    <stroke android:width="2dp"/>
    <!--solid for incase you want background color to edit box-->
    <solid android:color="@color/app_grey"/>
</shape>

创建editox_custom_bottom_radius.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!--Here Corner use for give curve to your edit text-->
    <corners android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp"/>
    <!--stroke is use to apply border on edit text-->
    <stroke android:width="2dp"/>
    <!--solid for incase you want background color to edit box-->
    <solid android:color="@color/app_grey"/>
</shape>

并将其应用于您的编辑框

    <LinearLayout
     android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

 <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Your Text"
        android:padding="@dimen/dimen10"
        android:background="@drawable/editbox_custom_top_radius"/>
<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Your Text"
        android:padding="@dimen/dimen10"/>
<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Your Text"
        android:padding="@dimen/dimen10"
        android:background="@drawable/editbox_custom_bottom_radius"/>
</LinearLayout>

尝试。

最新更新