目前我正在制作一个在操作栏上具有EditText的应用程序。我从以下链接找到了如何在操作栏上放置自定义视图:How to set a custom view in actionbar in android?。 我使用getSupportActionBar将EditText加载到操作栏上。如何自动选择操作栏上的自定义视图(EditText)?
getSupportActionBar.setCustomView(R.layout.actionbar_view);
它加载一个名为actionbar_view.xml的xml文件。该xml文件的代码如下所示。
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/searchfield"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Search for some app" >
</EditText>
的问题是,不象设置在区域下方的动作条上动作条编辑文本的所有正常EditTexts没有自动选择。有没有办法让自动选择的操作栏上的编辑文本?
顺便说一句,我确实看看下面的链接,How to focus and show soft keyboard when a EditText is shown in action bar?不幸的是我试图理解解决方案并适用于我的代码,但编辑文本仍然没有自动选择。对于堆栈溢出,我仍然很陌生,所以如果我没有提供足够的信息/代码来解决我的问题,请在评论中告诉我。谢谢!