2017-07-18 110 views
0

佈局是這樣聲明的。軟鍵盤不會自動彈出

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.guna.testapplication.MainActivity"> 

    <EditText 
     android:hint="@string/action_settings" 
     android:inputType="text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <requestFocus /> 
    </EditText> 
</RelativeLayout> 

活動聲明如下。

public class MainActivity extends AppCompatActivity { 

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

Activity加入了清單中。

<activity 
    android:name=".MainActivity" 
    android:label="@string/app_name"> 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 

     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 

當我運行這個應用程序時,我得到以下輸出。

enter image description here

我不知道爲什麼軟鍵盤不會自動彈出。任何幫助將不勝感激。

+0

我覺得你應該刪除在UR XML。可能是其工作 –

+0

@PrashantRP我試過..不行的 – Gunaseelan

+0

機器人:可調焦= 「真」 機器人:focusableInTouchMode = 「真」 ..這在我的佈局 –

回答

0

要強制軟鍵盤出現,你可以使用

EditText yourEditText= (EditText) findViewById(R.id.yourEditText); 
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); 
+0

不,我不想強​​制系統,我只是想知道爲什麼這個代碼不會自動彈出鍵盤。 – Gunaseelan

+0

你必須刪除這行你的xml

+0

@GowthamanM我高速檢查我的設備它正在工作 –

0

添加到您的EditText並嘗試

android:focusable="true" 
android:focusableInTouchMode="true" 
0
<activity 
android:name=".MainActivity" 
android:label="@string/app_name" 
android:windowSoftInputMode="adjustPan|adjustNothing"> 
<intent-filter> 
    <action android:name="android.intent.action.MAIN" />  
    <category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 
</activity> 

or in your activity 

EditText actionSettings= (EditText) findViewById(R.id.action_settings); 
InputMethodManager imm = (InputMethodManager) 
getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.showSoftInput(actionSettings, InputMethodManager.SHOW_IMPLICIT); 
0

添加您的清單裏面的活動這條線。

android:windowSoftInputMode="stateAlwaysVisible"