简体   繁体   English

如何将项目添加到顶部ActionBar?

[英]How can I add item to the top ActionBar?

I would like to add new icon to the top action bar, bet instead of adding to the top, the icon appear on the bottom of the screen. 我想在顶部操作栏添加新图标,下注而不是添加到顶部,图标显示在屏幕底部。 How can I add item to the top ActionBar? 如何将项目添加到顶部ActionBar?

XML: 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: Java的:

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_ygo_main, menu);
    return true;
}

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

To enable split action bar, simply add uiOptions="splitActionBarWhenNarrow" to your or manifest element. 要启用拆分操作栏,只需将uiOptions =“splitActionBarWhenNarrow”添加到您的或清单元素即可。

So if you want to have an item in the top. 所以,如果你想让一个项目在顶部。 Make sure that this line is NOT in your code. 确保此行不在您的代码中。

Check if you have android:uiOptions="splitActionBarWhenNarrow" in the activity definition in your AndroidManifest.xml. 检查AndroidManifest.xml中的活动定义中是否有android:uiOptions =“splitActionBarWhenNarrow”。 That's what makes action bar split to the bottom. 这就是动作栏分裂到底部的原因。

Check ActionBarSherlock for what you are doing. 检查ActionBarSherlock以了解您的操作。 It will provide ActionBar functionality on the older android versions and will use native ActionBar when it's supported. 它将在较旧的Android版本上提供ActionBar功能,并在支持时使用本机ActionBar。 It has sample application showcasing most of its settings http://actionbarsherlock.com/index.html 它有示例应用程序展示其大多数设置http://actionbarsherlock.com/index.html

If you don't want the bar to split, give that icon more space, for example removing 'withText' or shortening the title on the bar, and adding 'ifRoom' in showAsAction parameter. 如果您不希望该栏分割,请为该图标添加更多空间,例如删除“withText”或缩短栏上的标题,并在showAsAction参数中添加“ifRoom”。

Hope it helps 希望能帮助到你

<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 main line in mani feast u should do this to solve ur problem 这是玛尼盛宴的主线你应该这样做来解决你的问题

android:uiOptions="splitActionBarWhenNarrow" 机器人:uiOptions = “splitActionBarWhenNarrow”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM