1

Я новичок в android и работаю над демо-приложением. В том, что у меня есть активность, есть редактор в верхней части экрана и вы хотите показать клавиатуру в начале этой активности. I пробовал много способов, но ничто из этого не работает, может ли кто-нибудь помочь мне сортировать его?Мягкая клавиатура не открыта в android

layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/linearLayout" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:id="@+id/rl_hdr" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#16BBA1" 
     android:gravity="center_vertical" 
     android:padding="10dp"> 

     <ImageView 
      android:id="@+id/iv_back" 
      android:layout_width="25dp" 
      android:layout_height="22dp" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="0dp" 
      android:src="@drawable/ic_back_white" /> 

     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="40dp" 
      android:textColorHint="#939393" 
      android:singleLine="true" 
      android:layout_centerInParent="true" 
      android:hint="Search" 
      android:layout_marginLeft="5dp" 
      android:padding="5dp" 
      android:gravity="center_vertical" 
      android:drawablePadding="5dp" 
      android:layout_marginRight="5dp" 
      android:textSize="16dp" 

      android:imeOptions="actionDone" 
      android:cursorVisible="true" 
      android:layout_toRightOf="@+id/iv_back" 
      android:drawableRight="@drawable/ic_search" 
      android:background="@drawable/bg_et_actionbar" 
      android:id="@+id/et_search" /> 


    </RelativeLayout> 

     <FrameLayout 
      android:id="@+id/fragmentTimeline" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true" 

      android:layout_marginTop="0dp" /> 

</LinearLayout> 

manifest.xml

<activity 
      android:name="one.tusk.stush.SearchPostActivity" 
      android:label="Back" 
      android:parentActivityName="one.tusk.stush.activities.MainActivity" 
      android:screenOrientation="portrait" 
      android:windowSoftInputMode="stateAlwaysVisible" > 
      > 
     </activity> 

SerachPostActivity.java

public class SearchPostActivity extends FragmentActivity implements OnQueryTextListener, OnItemClickListener { 

    public EditText et_search; 
@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.search_post); 
. 
. 
. 
. 
et_search = (EditText)findViewById(R.id.et_search); 
    InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
     inputMethodManager.toggleSoftInputFromWindow(linearLayout.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0); 

et_search.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
      @Override 
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
       if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { 
        Log.i("Done pressed", "Enter pressed"); 
        search.searchPost(et_search.getText().toString().trim()); 
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0); 
       } 
       return false; 
      } 
     }); 


     et_search.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
      @Override 
      public void onFocusChange(View v, boolean hasFocus) { 
       if (hasFocus){ 
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.showSoftInput(et_search, InputMethodManager.SHOW_FORCED); 
       } else { 
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0); 
       } 
      } 
     }); 
+0

Где расположение XML пост это? –

+0

@MD - Пожалуйста, проверьте мой обновленный вопрос, я добавил макет. –

+1

do 'focus enabled = true' в' edit-text' –

ответ

1

Вы должны уделять внимание EditText.Try

android:focusable="true" 

в вашем EditText и откроет мягкую клавиатуру.

Попробуйте изменить ваш манифест

android:windowSoftInputMode="stateVisible" 

вместо

android:windowSoftInputMode="stateAlwaysVisible".

Если проблема не устранена, попробуйте открыть его с помощью программно

InputMethodManager imm = (InputMethodManager)getSystemService(
    Context.INPUT_METHOD_SERVICE); 
imm.showSoftInput(mEditText, 0); 

Вы можете также обратиться This answer на SO

+0

Ничего не случилось .. У меня есть добавила строку в edittext .. :( –

+0

@sulphuricAcid, пожалуйста, попробуйте обновленный ответ. –

+0

Я добавил этот код вручную в oncreat, но это ничего не делает. –

Смежные вопросы