2017-06-18 150 views
-4

edittext pic如何在Android的

喜邊框添加到文本框,我想在Android應用程序添加一個文本框,就像上圖中。我使用edittext控件,但無法顯示邊框。

+2

[有沒有簡單的方法來添加邊框到Android視圖的頂部和底部?](https://stackoverflow.com/questions/1598119/is-there-an-easy-way-到添加-A-邊境到最頂部和底部的-AN-機器人視圖) –

回答

0

創建繪製文件夾一個新的XML文件edit_text_border.xml,或將其命名爲任何你想要的,然後添加以下代碼:任何你想要

<shape 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 

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

<corners 
    android:bottomRightRadius="12dp" 
    android:bottomLeftRadius="12dp" 
    android:topLeftRadius="12dp" 
    android:topRightRadius="12dp"/> 

<stroke 
    android:color="@color/White" 
    android:width="1dp"/> 

更改邊框顏色和半徑值。然後在edittext將其設置爲這樣的背景。

<EditText 
android:id="@+id/edit_text" 
android:background:"@drawable/edit_text_border" 
/> 
0

嘗試以下代碼:

  1. 創建抽拉夾shape.xml文件,並在它寫以下代碼:

    <?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    
    <!-- Background Color --> 
    <solid android:color="#ffffff" /> 
    
    <!-- Border Color --> 
    <stroke android:width="1dp" android:color="#ff9900" /> 
    
    <!-- Round Corners --> 
    <corners android:radius="5dp" /> 
    </shape> 
    
  2. 現在在你的EditText裏面使用這個xml加入android:background="@drawable/shape"