2015-10-15 77 views
1

我知道我已經看到這個問題了一千多次,但還沒有找到一個有效的答案。在我的應用程序中,我有一個Edittext框。當我在模擬器或手機上運行應用程序時,在編輯文本中輸入時沒有文字顯示。光標移動,我可以得到我輸入的值,輸入時只顯示任何內容。我試着改變文字的顏色,背景的顏色和我遇到的其他所有解決方案,但沒有任何成效。Android edittext鍵入的文本不顯示

這裏是我的EditText上

<EditText android:id="@+id/editChannel_no" 
     android:layout_toRightOf="@+id/Channo" 
     android:layout_width="35dp" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/Channo" 
     android:inputType="number" 
     android:hint="2" 
     android:cursorVisible="true" /> 

這裏XML與EditText上

EditText editChannel_no; 
    Button btnSearch; 
    Button btnShowAll; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     //<item android:id="@+id/action_settings" android:title="@string/action_settings" 
     //android:orderInCategory="100" app:showAsAction="never" /> 


     editChannel_no=(EditText)findViewById(R.id.editChannel_no); 
     editChannel_no.requestFocus(); 
     btnSearch=(Button)findViewById(R.id.btnSearch); 
     btnShowAll=(Button)findViewById(R.id.btnShowAll); 

     editChannel_no.setTextColor(Color.BLACK); 

我一直在努力,現在找到2天的解決方案,任何人都使用的唯一代碼解決這個問題將是我的英雄。

感謝

+0

你可以請發佈完整的XML? – Santanu

+0

出於好奇,是否將layout_width設置爲像match_parent這樣的區別?另外,如果id.Channo元素的高度太小,編輯文本的大小就會縮小。 – jyanks

+0

它適用於我可能會幫助其他人完整,以及,http://stackoverflow.com/questions/21711237/edittext-in-android-doesnt-show-text-when-typing-while-using-the-on-屏幕KEYB/41425153#41425153 –

回答

0

我跑的你同樣的XML代碼,在我的情況下工作正常enter image description here
你可以做的是

  1. 重新啓動Android Studio中,如果你使用它,否則IDE你正在使用。
  2. 同步。您的項目使用下面的圖標。

再次運行上述應該工作。

enter image description here

1

嘗試了你的代碼 - 在我的模擬器它的工作如預期(我用Genymotion)。你確定你在編輯文字中輸入數字嗎? android:inputType =「number」指定你只輸入數字作爲輸入。 enter image description here

0

畢竟這個時候,問題在於edittext接近標題欄。顯示我在android編程中有多少noob。