2017-07-19 36 views
0

當鍵盤處於全屏模式時,我的EditText提示不會改變。我怎樣才能解決這個問題? Connecting...是原始提示。當鍵盤全屏時,提示不會改變。 !當鍵盤處於全屏模式時,EditText提示不會改變?

enter image description here

這裏是我的代碼:

public class MainActivity extends AppCompatActivity { 

    EditText editText; 

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

     final int intervalTime = 10000; // 10 sec 
     Handler handler = new Handler(); 
     handler.postDelayed(new Runnable() { 
      @Override 
      public void run() { 

       editText = (EditText) findViewById(R.id.messageEditText); 
       editText.setHint("new hint"); //set the new hint! 

      } 
     }, intervalTime); 
    } 
} 

XML:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.me.myapplication.MainActivity"> 

    <EditText 
     android:id="@+id/messageEditText" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:layout_weight="1" 
     android:hint="Connecting..." 
     android:inputType="text" 
     android:textSize="15sp" /> 

</android.support.constraint.ConstraintLayout> 
+0

哪裏是你的XML –

+0

@NileshRathod我要把它現在 –

+0

沒有得到你的問題 –

回答

0

試試這個

myEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
    public void onFocusChange(View v, boolean hasFocus) { 
     if (hasFocus) 
      myEditText.setHint("new hint"); 
     else 
      myEditText.setHint(""); 
    } 
}); 
+0

這不是我想要的。 你可以看到EditText提示是「新提示」,但當我打開全屏幕鍵盤時,它是「連接...」?是或否? –

+0

但在xml中,您將提示設置爲android:hint =「正在連接...」 –

+0

是的。但在我的代碼'editText.setHint(「new hint」);' –

0

嘗試在xml設置hintandroid:hint="write your hint here"

+0

我將它設置爲'android:hint =「正在連接」.',如你所見。 –

+0

仔細檢查我的問題..... –

+0

你的提示不會在鍵盤打開時消失,當你開始寫字時它會消失 –

相關問題