带有椭圆形角的Autocompletetextview

时间:2014-07-18 11:28:54

标签: android xml background shape android-drawable

我想创建图中所示的自动完成文本视图的形状,文本应该位于其中心。

enter image description here

目前我正在尝试将其实现为

<item>
    <shape android:shape="rectangle" >
        <corners android:radius="15dip" />

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

        <padding
            android:bottom="5dip"
            android:left="15dip"
            android:right="15dip"
            android:top="5dip" />
    </shape>
</item>

<AutoCompleteTextView
  android:id="@+id/autoComp"
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:gravity="center"
  android:background="@drawable/bg_autocompletetext"
  android:textColor="@color/white"
</AutoCompleteTextView>

但它只会使textview的角落变圆。它确实使它完全圆。请为其指定任何解决方案。

5 个答案:

答案 0 :(得分:2)

试试这个形状代码

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

   <corners
    android:radius="100dp"/>
   <solid
    android:color="#2137FF"/>
   <size
    android:width="250dp"
    android:height="60dp"/>
</shape> 

enter image description here

试试这个tool

答案 1 :(得分:0)

最好使用9个补丁图像作为TextView的背景。

使用9个补丁图像,您可以为不同的分辨率设备设置合适的分辨率。它会给您更好的结果。

答案 2 :(得分:0)

您编写了一个单独的xml布局(shape.xml),其代码为:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">
 <solid android:color="#DCDCDC" />    
<stroke android:width="2.5dp" 
android:color="#DCDCDC" />
<corners
android:radius="10dp"/>
</shape>

然后在你的主要版面中添加:

<AutoCompleteTextView
android:id="@+id/autoComp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:background="@drawable/shape"
android:textColor="@color/white"
</AutoCompleteTextView>

希望得到这个帮助。

答案 3 :(得分:0)

试试这个,使用圆角文字视图

<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_textview.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#284A89" />
    <corners
        android:bottomLeftRadius="30dp"
        android:bottomRightRadius="30dp"
        android:topLeftRadius="30dp"
        android:topRightRadius="30dp" />
</shape>

答案 4 :(得分:0)

在可绘制对象“ searchtextbox_border.xml”中添加以下文件

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <corners
        android:radius="100dp"/>
    <stroke android:color="@color/light_grey"
        android:width="1dp">
    </stroke>
</shape>

然后将其作为背景添加到您的AutocompleteTextview中,如下所示:

<AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="32dp"
        android:padding="@dimen/padding_10dp"
        android:background="@drawable/searchtextbox_border"
        android:hint="Search" />
相关问题