Android 布局的边框

Android 布局的边框,android,border,android-linearlayout,Android,Border,Android Linearlayout,我正试图在我的布局周围画一个这样的边框 但我正在尝试的只是改变布局颜色。 没有任何边界 我的代码是 <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <stroke android:width="1dp" android:color="#eedfcc" andro

我正试图在我的布局周围画一个这样的边框

但我正在尝试的只是改变布局颜色。 没有任何边界

我的代码是

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

<stroke android:width="1dp"

        android:color="#eedfcc"
        android:background="#000080"/>

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

为什么不起作用?

请尝试以下代码:

<EditText 
    android:id="@+id/edittext1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/textboxes"
     /> 

在名为“textboxs”的可绘制文件夹中创建xml文件,并在其中编写以下代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
    android:color="#f269be"
    android:width="2dp" />
<solid
    android:color="#ffffff" />
</shape>

对于圆角边框,写下以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#009FFFFF"/>
<corners android:radius="10px"/>
<padding android:left="1dp" android:top="2dp" android:right="2dp" android:bottom="2dp" /> 
<stroke android:width="2dp" android:color="#AAAAAA" />
</shape>

试试这个:

步骤1:在项目的drawables目录(res/drawable/layout\u border.xml)中创建文件
layout\u border.xml


第二步:

<EditText 
    android:id="@+id/edittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/layout_border"
     /> 

创建一个文件“res/drawable/my_border.xml”并定义一个形状:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="4dp" android:color="#FF00FF00" />
    <solid android:color="#ffffff" />
    <padding android:left="7dp" android:top="7dp"
            android:right="7dp" android:bottom="7dp" />
    <corners android:radius="4dp" />
</shape>

解决方案1:

<EditText 
    android:id="@+id/edittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/layout_border"
     /> 
我的编辑文本

 <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >    
    <!-- Color of the border -->
    <stroke
      android:width="2dp"
      android:color="#FF0000" />
    <!-- Use this if you want to round your Corners -->
    <corners android:radius="5dp" />
    <!-- Use this attribute if you want add some paddings -->
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
    </shape>
解决方案2:

<EditText 
    android:id="@+id/edittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/layout_border"
     /> 
使用此9面片可绘制作为EditText的背景


你没有像这样定义你的形状,实际上它不是完全矩形的,真的是一个很好的解决方案。快速、简单且有很好的文档记录。也能够在Android Studio 2.1.1中轻松实现。
 android:background="@drawable/my_edittext_bg"