2012-07-03 37 views
10

tôi đang cố gắng để tạo ra một biên giới xung quanh bố trí của tôi như thế nàyBorder cho bố trí

two text areas with rounded borders

Nhưng những gì tôi đang cố gắng chỉ cần thay đổi màu sắc bố trí. Không tạo bất kỳ đường viền nào.

Mã của tôi là

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

Tại sao nó không hoạt động ra?

+0

bạn didnt xác định loại hình của bạn như thế này

+0

thực sự nó không phải là hình chữ nhật hoàn toàn – MBMJ

Trả lời

33

hãy thử cách này:

BƯỚC 1: Tạo tập tin trong thư mục layout_border.xml drawables của dự án của bạn (res/drawable/layout_border.xml):

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FFFFFF"/> 
    <stroke android:width="3dip" android:color="#B1BCBE" /> 
    <corners android:radius="10dip"/> 
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> 
</shape> 

BƯỚC 2:

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

Giải pháp thực sự tốt đẹp. Nhanh chóng và dễ dàng và độc đáo tài liệu. Có thể thực hiện dễ dàng trong Android Studio 2.1.1. – raddevus

1

Hãy thử mã này:

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

Và tạo file xml trong thư mục drawable tên 'textbox' và viết những dòng này Codein rằng:

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

Fro biên giới tròn góc, viết những dòng này:

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

Tạo một file "res /drawable/my_border.xml "và xác định hình dạng:

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

T hen thêm này như là một nền tảng bên trong thẻ bố trí của bạn:

android:background="@drawable/my_border" 
2

Giải pháp 1:

my_edittext_bg

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

Bây giờ thiết lập này là nền tảng của chỉnh sửa văn bản của bạn

android:background="@drawable/my_edittext_bg" 

Giải pháp 2:

Sử dụng 9-patch này drawable như nền của EditText bạn

enter image description here

Các vấn đề liên quan