How to add an item to the top ActionBar?

I would like to add a new icon to the top action bar, instead of adding to the top, the icon appears at the bottom of the screen. How to add an item to the top ActionBar?

XML:

<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/preferences" android:icon="@drawable/preferences" android:title="Preferences" android:showAsAction="always|withText"/> <item android:id="@+id/help" android:title="Help" android:icon="@drawable/ic_action_search" /> </menu> 

Java:

 public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.activity_ygo_main, menu); return true; } 
+6
source share
4 answers

Taken from http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar

To enable the split action bar, simply add uiOptions = "splitActionBarWhenNarrow" for yours or manifest.

So, if you want to have an item at the top. Make sure this line does NOT belong to your code.

+6
source

Check if you have Android: uiOptions = "splitActionBarWhenNarrow" in the activity definition in your AndroidManifest.xml. This is what makes the action bar split to the bottom.

Check out ActionBarSherlock for what you do. It will provide ActionBar functionality for older versions of Android and will use its own ActionBar, if supported. It has an example application that demonstrates most of its settings http://actionbarsherlock.com/index.html

+1
source

If you do not want the panel to be divided, add this icon more space, for example, removing "withText" or shortening the title on the panel and adding the "ifRoom" parameter to the showAsAction parameter.

Hope this helps

0
source

 <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:uiOptions="splitActionBarWhenNarrow" > <activity android:name="com.example.androidactionbarbottam.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 

This is the main line in the manifesto, and you have to do it to solve ur problem

android: uiOptions = "splitActionBarWhenNarrow"

0
source

Source: https://habr.com/ru/post/921860/


All Articles