[android] Round corner, change background when focuses, overlay text in EditText

screenshot_2014-11-26_PM 8.40.46

 

바로 이런걸 만들어야한다.

이상하게 이건 해도해도 자꾸 까먹어서 블로그에 남겨놔야겠다

 

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
  <solid android:color="#fff" />  
  <corners android:radius="50dip" />
</shape>

 

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
  <solid android:color="#fff" />
  <corners android:radius="50dip" />
  <stroke
    android:width="3dip"
    android:color="#6D94E5" />
</shape>

 

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/bg_my_info_input_field_focused" android:state_focused="true"/>
  <item android:drawable="@drawable/bg_my_info_input_field_normal"/>
</selector>

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#ff0"
  android:orientation="vertical"
  android:paddingEnd="25dp"
  android:paddingStart="25dp" >
  
  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:focusable="true"
    android:focusableInTouchMode="true" >
    
    <EditText
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      android:background="@drawable/bg_my_info_input_field"
      android:gravity="center_vertical|end"
      android:hint="키"
      android:inputType="numberDecimal"
      android:paddingBottom="10dp"
      android:paddingEnd="60dp"
      android:paddingTop="10dp" />
    
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentEnd="true"
      android:layout_centerVertical="true"
      android:layout_marginEnd="20dp"
      android:text="cm"
      android:textAppearance="?android:attr/textAppearance"
      android:textStyle="bold" />
  </RelativeLayout>
  
  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:focusableInTouchMode="true" >
    
    <EditText
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      android:background="@drawable/bg_my_info_input_field"
      android:gravity="center_vertical|end"
      android:hint="체중"
      android:inputType="numberDecimal"
      android:paddingBottom="10dp"
      android:paddingEnd="60dp"
      android:paddingTop="10dp" />
    
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentEnd="true"
      android:layout_centerVertical="true"
      android:layout_marginEnd="20dp"
      android:text="kg"
      android:textAppearance="?android:attr/textAppearance"
      android:textStyle="bold" />
  </RelativeLayout>
</LinearLayout>