Опитвам се да добавя бутона за търсене към лентата с действия на Android, като следвам този урок: https://developer.android.com/training/basics/actionbar/adding-buttons.html
Промених от minSdkVersion до 11 в моя манифест.
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
Добавих елемента action_search във файл main.xml
, намиращ се в папка menu
:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
<item android:id="@+id/action_search"
android:title="@string/action_search"
android:icon="@drawable/ic_action_search"
android:showAsAction="always|collapseActionView"
android:actionViewClass="android.widget.SearchView"/>
</menu>
Eclipse вече е предоставил метода за менюто, което не съм променил:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
Добавих низа към моите strings.xml
: <string name="action_search">Search</string>
и включих ic_action_search.png
в моите папки с възможност за рисуване.
Няма грешки при стартиране. Виждам елемента от менюто Настройки в препълването. Но не виждам никъде бутона за търсене.