2012-09-13 41 views
0

在我的Android應用程序中,我有一個文本字段,顯示「您要採取多少操作」。如何在用戶輸入任何字符時替換文本字段中的文本

我希望文本自動刪除,並替換爲用戶在輸入該文本字段時輸入的內容。

例如:如果用戶輸入一個字符,它會自動從文本字段中刪除「您要採取多少」並將其替換爲輸入的一個字符。

+0

替換更改後的文字關注這個文本字段? –

回答

2

在XML文件中使用

android:hint="how much would you like to take" 

TextView定義

(嗯,這應該是類似"@string/how_much"how_much字符串中的strings.xml,但說實話...)

+0

非常感謝! –

1

它被稱爲android:hint屬性EditText你可以將它設置到你的xml文件中。

就是這樣的。

<EditText 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:hint="how much would you like to take" /> 
1

在XML試試這個

使用這下面的代碼android:hint="how much would you like to take"

<EditText 
    android:id="@+id/edtName" 
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:layout_below="@+id/txtName"  
    android:layout_marginRight="5dip" 
    android:hint="how much would you like to take" 
    android:inputType="textCapSentences" 
    /> 

希望它可以幫助

相關問題