【问题标题】:Can you add a textview to an action bar? If not, a sub actionbar? [closed]您可以将文本视图添加到操作栏吗?如果没有,子操作栏? [关闭]
【发布时间】:2013-04-23 20:15:10
【问题描述】:

我想在我的应用操作栏(显示标题、应用图片等的栏)下方有一个“信息栏/文本视图”。

我的应用程序上有标签,我想要标签上方的信息栏,操作栏的正下方。我知道如何更改主布局 xml 以使用布局将其放在选项卡下方,但我不知道是否可以将栏放在选项卡上方。我不能把它放在标签上方,因为我认为它们是操作栏的“一部分”。

【问题讨论】:

  • 嗯。我一直想知道同样的事情。我对新功能的了解并不多

标签: android layout android-fragments textview android-actionbar


【解决方案1】:

为信息栏和选项卡创建 xml 布局。例如:

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

    <TextView
        android:id="@+id/infobar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Info Bar" />

    <RelativeLayout
        android:id="@id/tab_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/infobar" >
    </RelativeLayout>

</RelativeLayout>

用您自己的布局替换信息栏文本视图。注意相对布局“tab_layout”?那将是选项卡将占用的空间。遵循示例here。取自链接上的示例:

/* The following are each of the ActionBar.TabListener callbacks */

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // Check if the fragment is already initialized
        if (mFragment == null) {
            // If not, instantiate and add it to the activity
            mFragment = Fragment.instantiate(mActivity, mClass.getName());
            ft.add(android.R.id.content, mFragment, mTag);
        } else {
            // If it exists, simply attach it in order to show it
            ft.attach(mFragment);
        }
    }

将这个:ft.add(android.R.id.content, mFragment, mTag) 更改为这个ft.add(R.id.tab_layout, mFragment, mTag)。请注意,我们使用了自己的布局而不是 android.R.id.content。

【讨论】:

    猜你喜欢
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多