2017-02-17 25 views
-3

你好傢伙我想到了一個特定的設計,我想在我的android應用程序中實現,但它對我來說很難想出辦法做到這裏是我的尋找。如何自定義設計android編輯文本

我正在尋找: enter image description here

<LinearLayout 
    android:background="#C5CAE9" 
    android:layout_width="match_parent" 
    android:layout_height="30dp" 
    android:orientation="horizontal"> 

    <android.support.design.widget.TextInputLayout 
     android:padding="5dp" 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:background="#3F51B5" 
     android:layout_height="match_parent"> 

     <android.support.design.widget.TextInputEditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/form_username"/> 

`

+1

哪一部分是困難的? – bc004346

回答

1

可以使用九補丁做到這一點。 NinePatch圖像是PNG圖像,您可以在其中指定要允許/拒絕文本的區域。因此,您可以設計想要的圖像(使用圖標),並拒絕在圖標部分上書寫文字,並在完成後將圖像設置爲背景。在Android Studio中,有一個有用的WYSIWIG工具。有關詳細信息,請看看here

0

我會說這樣的事情:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="100dp" 
android:layout_height="wrap_content" 
android:background="@drawable/your_background_with_orange_stroke"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:src="@drawable/your_left_one_drawable"/> 

<android.support.design.widget.TextInputLayout 
    android:padding="5dp" 
    android:layout_width="0dp" 
    android:layout_weight="1" 
    android:background="#3F51B5" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.TextInputEditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="@string/form_username"/> 
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:src="@drawable/your_right_pen_drawable"/> 

0

嘗試,讓看,如果這是你想要的。

創建繪製shape.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <corners android:radius="50dp" /> <-- change it to your need radius 
    <stroke android:width="3px" android:color="@color/chocolate" /> 
    <solid android:color="@color/grey"/> 
</shape> 

創建佈局

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="15dp"> 

    <EditText 
      android:id="@+id/keyword" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:hint="Type keyword..." 
      android:padding="15dp" 
      android:textSize="16sp" 
      android:inputType="textPersonName" 
      android:background="@drawable/shape"/> 

    <ImageView 
      android:id="@+id/icon" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:padding="10dp" 
      android:tint="@color/chocolate" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:src="@drawable/icon_calendar"/> 
</RelativeLayout> 
相關問題