【问题标题】:Add custom title bar using ActionBar使用 ActionBar 添加自定义标题栏
【发布时间】:2013-07-31 09:48:40
【问题描述】:

我想在 FragmentActivity 的子项中添加一个自定义标题栏,我有一个标题栏布局,我就是这样做的。

    final ActionBar actionBar = getActionBar();

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.title_bar);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.addTab(actionBar.newTab().setText("Tab0").setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("Tab1").setTabListener(this));
    actionBar.addTab(actionBar.newTab().setText("Tab2").setTabListener(this));

但问题是标题栏显示在选项卡下方。我想要导航标签上方的标题栏。

这是我的 title_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/titleBar"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/black" >

    <ImageView
        android:id="@+id/titleBarMenuBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/menu_btn" />


    <TextView
        android:id="@+id/titleBarLocation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/titleBarMenuBtn"
        android:text="Location"
        android:textColor="@color/white"
        android:textSize="16dip" />


    <TextView
        android:id="@+id/titleBarUpdateDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/titleBarMenuBtn"
        android:layout_alignLeft="@+id/titleBarLocation"
        android:layout_alignParentRight="true"
        android:text="Updated: 30/Jul/2013"
        android:textColor="@color/white" />

</RelativeLayout>

我看到了this 的帖子,但我的标签显示在标题栏上方。

谢谢

【问题讨论】:

标签: android android-actionbar custom-titlebar


【解决方案1】:

在您的自定义布局上方显示选项卡是预期的默认行为。尽管有一些方法可以覆盖它。我发现发布了可能的解决方案:#1#2

此外,sherlock 操作栏的行为方式似乎相同。

【讨论】:

  • 感谢您的回答...这是否意味着我必须制作带有标签的自定义标题栏,并且必须添加处理滑动和标签位置更改的功能?
  • 是的,这似乎是最好的解决方案(参考解决方案 #1)。您应该记住,您覆盖了系统默认(和用户预期的)行为。这就是为什么它有点复杂:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-13
  • 1970-01-01
  • 2011-09-04
  • 1970-01-01
  • 2021-12-19
  • 1970-01-01
  • 2013-03-11
相关资源
最近更新 更多