2014-09-26 63 views
2

我正在開發一個應用程序。在XML中佈局我正在編輯文本並從drawable設置它的背景。Android:編輯文本提示

現在我想要的是 - 我想設置提示繪製,並且還想設置圖像中顯示的文本。 enter image description here

我試圖設置提示,但是當我設置提示時。沒關係。但是當我設置了那個時候隱藏的140個字符。

當用戶打算輸入時,我想保留那140個字符。而每個角色所剩下的角色都會減少。

因此,如何做到這一點請指導我...

+0

使用'TextView'來顯示剩餘字符和'EditText'上的'TextWatcher'來更新「chars left」計數器。 – reVerse 2014-09-26 13:26:54

+0

你想要做的事情不是** android:提示**。嘗試第一位評論員的建議。 – 2014-09-26 13:29:12

回答

6

使用TextWatcherEdiText和使用TextView顯示剩餘的字符

private TextView mTextView; 
private EditText mEditText; 
private final TextWatcher mTextEditorWatcher = new TextWatcher() { 
    public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
    } 

    public void onTextChanged(CharSequence s, int start, int before, int count) { 
     //This sets a textview to the current length 
     mTextView.setText(String.valueOf(s.length())); 
    } 

    public void afterTextChanged(Editable s) { 
    } 
}; 
mEditText.addTextChangedListener(mTextEditorWatcher); 
0

你必須考慮你的EditText在一個相對佈局所以你可以設置一個textview,它的值將在輸入單個字母時改變。因此,您需要爲此實現Textwatcher。