Android的ActionBarSherlock顶酒吧 [英] Android ActionBarSherlock Top Bar

查看:142
本文介绍了Android的ActionBarSherlock顶酒吧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个操作栏类似Foursquare的。我要的是标签,如朋友,探索和我。此外,标签上面我想有一个自定义布局,其中包括一些按钮,如方正的标志,刷新和办理的四角。我创建的标签,但我不能改变上述选项卡中ActionBarSherlock布局。我该如何解决这个问题呢?

I want to have an Action Bar like foursquare. What I want is tabs such as Friends, Explore and Me. Also, above the tabs I want to have a custom layout that includes some buttons such as foursquare logo, Refresh and Check-In in foursquare. I created tabs but I could not change the layout above tabs in ActionBarSherlock. How can I solve this problem?

推荐答案

要实现四方的样子,你不必去考虑创建标签上面的一个布局。当使用的ActionBar福尔摩斯,你只需要担心的:

To achieve a Foursquare look you do not need to be thinking of creating a layout above the tabs. When using Actionbar Sherlock you only need to worry about:

  1. 在制作背景的顶栏
  2. 在制作标识的顶栏
  3. 在ActionbarSherlock将用于填充顶部带有按钮的menu.xml文件的文件添加项目(只要使用的ActionBar福尔摩斯式的风格被连接到THW活动)。

因此​​,对于1和2。这是所有关于使用styles.xml文件(应驻留在值文件夹中的res文件夹),像这样:

So, for 1. and 2. it's all about using styles.xml file (should reside in the values folder in the res folder) like so:

<style name="Theme.Example" parent="Theme.Sherlock">
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <item name="absForceOverflow">true</item>       
</style>

<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar.Solid">
    <item name="background">@drawable/actionbar_background</item> <-- the background for top bar
    <item name="icon">@drawable/actionbar_logo</item> <-- the logo that goes top left in the top bar
    <item name="backgroundSplit">@drawable/bg_striped_split</item> <-- the image used between the menu items
</style>

有关3.所有你需要做的是在menu.xml文件创建菜单项(应该驻留在菜单文件夹(如果不存在,创建一个在资源文件夹)):

For 3. all you need to do is create menu items under menu.xml (should reside in the menu folder (if not there, create one in the res folder)):

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">     

<item android:id="@+id/menu_prefs"
      android:icon="@drawable/settings_icon"
      android:title="Preferences"
      android:showAsAction="ifRoom" /> 
</menu>

您需要做的,看看菜单项的最后一件事是在活动中使用这些函数:

The last thing you have to do to see the menu items is use these functions in the activity:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

public boolean onOptionsItemSelected (MenuItem item) {

    Intent intent;

    switch (item.getItemId())
    {   
    case R.id.menu_prefs:

        // Launch Preference Activity
        intent = new Intent(getBaseContext(), Preferences.class);           
        startActivity(intent);
        break;
    }

    return false;
}

这篇关于Android的ActionBarSherlock顶酒吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆