我有一个Fragment(兼容版本)的EditText布局.我正在使用a ViewFlipper在片段之间翻转.当我遇到这个问题时Fragment,软键盘会自动打开.这不是我想要的.这是我试图阻止它或隐藏它.
尝试:
android:descendantFocusability="beforeDescendants"
Run Code Online (Sandbox Code Playgroud)
在片段的主视图上
尝试:
android:windowSoftInputMode="stateHidden"
Run Code Online (Sandbox Code Playgroud)
和
android:windowSoftInputMode="stateAlwaysHidden"
Run Code Online (Sandbox Code Playgroud)
在活动的清单中
尝试:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mViewPager.getChildAt(position).getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
在我的ViewPager的OnPageChangeListener上
尝试:
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(voucherView.findViewById(R.id.redeem_mobile_number).getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
在我的片段中的onCreateView中
尝试:
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getView().findViewById(R.id.redeem_mobile_number).getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
在我的片段中的onStart中
尝试:
voucherView.findViewById(R.id.redeem_mobile_number).clearFocus();
Run Code Online (Sandbox Code Playgroud)
在我的片段中的onCreateView中
在我看来,onPageChangeListener就是这样做的地方,因为其他调用在软键盘实际打开之前发生.任何帮助都会很棒.
小智 8
<LinearLayout
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
>
<EditText
android:id="@+id/retailer_search_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
跟着它吧.EditText应该在LinearLayout中.
你试过这个吗?
<activity
android:name=".YourActivityName"
android:configChanges="keyboardHidden|orientation"
android:windowSoftInputMode="stateHidden" />
Run Code Online (Sandbox Code Playgroud)
编辑:
试试这个(我现在这是一个糟糕的但尝试这个):)
Thread splashTread = new Thread() {
@Override
public void run() {
try {
sleep(1);
} catch (InterruptedException e) {
// do nothing
} finally {
runOnUiThread(new Runnable() {
public void run() {
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(youreditText.getWindowToken(), 0);
}
});
}
}
};
splashTread.start();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28088 次 |
| 最近记录: |