2016-09-19 4 views
-1

두 개의 서로 다른 텍스트가 단일 EditText에 나타나길 원합니다.하나의 EditText에 두 개의 텍스트를 표시하는 방법

toBeAchieved

나는

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <EditText 
     android:textSize="25dp" 
     android:editable="false" 
     android:textColor="@color/white" 
     android:text="+91" 
     android:layout_marginTop="20dp" 
     android:theme="@style/Regestration_edit_text" 
     android:id="@+id/rhs_country_code" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <EditText 
     android:textColorHint="@color/white" 
     android:textSize="25dp" 
     android:hint="Mobile Number" 
     android:layout_marginTop="20dp" 
     android:theme="@style/Regestration_edit_text" 
     android:id="@+id/rhs_mobile_number" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

results

이 사람이 나를 도울 수이 같은 시도?

+1

(bg_line_edit_text)을 그릴 수있다. –

+5

'editText.setText ("+ 91"+ mobileNumber); ' –

+0

@MuhammadBabar –

답변

1

을 Heres 레이아웃

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/bg_line_edit_text" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/rhs_country_code" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="8dp" 
      android:layout_marginRight="4dp" 
      android:layout_marginEnd="4dp" 
      android:layout_marginTop="20dp" 
      android:background="@null" 
      android:text="+91" 
      android:textSize="25dp" /> 

     <EditText 
      android:id="@+id/rhs_mobile_number" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="8dp" 
      android:layout_marginTop="20dp" 
      android:background="@null" 
      android:hint="Mobile Number" 
      android:textSize="25dp" /> 

    </LinearLayout> 

</LinearLayout> 

그리고 여기 당신이 문자열을 모두 CONCAT하고 표시 할 수 있습니다

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:bottom="1dp" 
     android:left="-2dp" 
     android:right="-2dp" 
     android:top="-2dp"> 
     <shape android:shape="rectangle"> 
      <stroke 
       android:width="1dp" 
       android:color="@android:color/black"/> 
      <solid android:color="@android:color/transparent"/> 
     </shape> 
    </item> 
</layer-list> 
관련 문제