首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >软键盘不显示onTouch自定义EditText在ActionBar中

软键盘不显示onTouch自定义EditText在ActionBar中
EN

Stack Overflow用户
提问于 2015-05-11 11:21:39
回答 3查看 711关注 0票数 1

我有一个非常类似于pinterest搜索框的复杂的自定义视图。这个组件只是在一个EditText中显示Button和多个Button

组件在任何Fragment布局中都可以很好地处理相同的布局文件。这意味着当用户单击该组件时,soft-keyboard将显示EditText __并正常工作,当我尝试将此组件添加到自定义actionbar时,它将无法工作。这意味着,单击它不会显示soft-keyboard

我认为这是一个焦点问题,但我尝试调试,并且EditText onTouch方法正在正常地被调用。我还尝试使用descendantFocusability参数,但没有得到任何结果。

这是我的自定义ActionBar初始化

代码语言:javascript
复制
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

代码语言:javascript
复制
<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之间的焦点有冲突

EN

回答 3

Stack Overflow用户

发布于 2015-05-11 11:41:36

在编辑文本所在的活动中,活动类在清单文件中声明,您需要添加下面的代码行,如下所示

内部活动android:windowSoftInputMode="stateAlwaysVisible“

票数 0
EN

Stack Overflow用户

发布于 2015-05-11 11:52:18

您可以尝试将此行添加到操作栏按钮侦听器中。

(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);your_view.getWindow().setSoftInputMode

票数 0
EN

Stack Overflow用户

发布于 2015-08-28 21:34:37

可以在设置自定义搜索视图后调用以下代码。应该将searchView初始化为android.widget.searchview。

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30166369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档