我有一个非常类似于pinterest搜索框的复杂的自定义视图。这个组件只是在一个EditText中显示Button和多个Button。
组件在任何Fragment布局中都可以很好地处理相同的布局文件。这意味着当用户单击该组件时,soft-keyboard将显示EditText 但__并正常工作,当我尝试将此组件添加到自定义actionbar时,它将无法工作。这意味着,单击它不会显示soft-keyboard。
我认为这是一个焦点问题,但我尝试调试,并且EditText onTouch方法正在正常地被调用。我还尝试使用descendantFocusability参数,但没有得到任何结果。
这是我的自定义ActionBar初始化
public void initializeCustomActionBar() {
android.support.v7.app.ActionBar mActionBar = ((ActionBarActivity) getActivity()).getSupportActionBar();
mActionBar.setDisplayShowHomeEnabled(true);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(getActivity());
View customView = mInflater.inflate(R.layout.actionbar_layout, null);
mActionBar.setDisplayShowCustomEnabled(true);
mActionBar.setCustomView(customView);
}下面是我定制的ActionBar布局xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.my.package.customSearch
android:id="@+id/pdt_actionbar_searchbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp" />
我正在以编程方式构建这个没有XML文件的自定义布局。由于某些原因,我无法发布构建此布局的代码,但我绘制了一个图像,详细说明了ActionBar布局的层次结构。
注意:我使用的是NavigationDrawer左菜单。我认为它的左菜单Button和我的EditText之间的焦点有冲突

发布于 2015-05-11 11:41:36
在编辑文本所在的活动中,活动类在清单文件中声明,您需要添加下面的代码行,如下所示
内部活动android:windowSoftInputMode="stateAlwaysVisible“
发布于 2015-05-11 11:52:18
您可以尝试将此行添加到操作栏按钮侦听器中。
(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);your_view.getWindow().setSoftInputMode
发布于 2015-08-28 21:34:37
可以在设置自定义搜索视图后调用以下代码。应该将searchView初始化为android.widget.searchview。
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
}
searchView.requestFocus();对于android:windowSoftInputMode="stateAlwaysVisible“,使用setOnFocusChangeListener或setOnFocusChangeListener
https://stackoverflow.com/questions/30166369
复制相似问题