目前我正在製作一個在操作欄上具有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?不幸的是我試圖理解解決方案並適用於我的代碼,但編輯文本仍然沒有自動選擇。對於堆棧溢出,我仍然很陌生,所以如果我沒有提供足夠的信息/代碼來解決我的問題,請在評論中告訴我。謝謝!