【发布时间】:2015-07-16 21:11:23
【问题描述】:
目前我正在制作一个在操作栏上有一个 EditText 的应用程序。我通过以下链接了解了如何在操作栏上放置自定义视图:How to set a custom view in actionbar in android?。 我使用 getSupportActionBar 将 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>
问题在于,与放置在操作栏下方区域的所有普通 EditText 不同,操作栏上的编辑文本不会自动选择。有没有办法让操作栏上的这个编辑文本自动被选中?
顺便说一句,我确实查看了以下链接,How to focus and show soft keyboard when a EditText is shown in action bar? 不幸的是,我试图理解解决方案并将其应用于我的代码,但编辑文本仍未自动选择。我对堆栈溢出还是很陌生,所以如果我没有提供足够的信息/代码来解决我的问题,请在 cmets 中告诉我。谢谢!
【问题讨论】:
标签: android xml android-actionbar android-edittext