你可以添加一个TextView一个动作吧?如果不是这样,一个子动作条?动作、你可以、如果不是、个子

2023-09-12 02:58:41 作者:森树白云

我想有一个信息栏/ TextView的右下面我的应用程序的操作栏(栏写着标题,应用程序的图片,等等)。

I wanted to have a "info bar/textview" right below my App's action bar (the bar that says the title, app picture, etc).

我有我的应用程序选项卡,和我想要的信息栏上方的标签,右下方的操​​作栏。我知道如何更改主的布局XML来把它使用布局选项卡下面,但我不能弄清楚是否有可能把标签上方的酒吧。我不能把它的标签上面,因为我觉得他们的操作栏的部分。

I have tabs on my application, and I wanted the infobar ABOVE the tabs, right below the action bar. I know how to change the main' layout xml to put it below the tabs using a layout, but I can't figure out if it's possible to place the bar above the tabs. I can't put it above the tabs because I think they're 'part' of the action bar.

推荐答案

创建信息栏和标签的XML布局。例如:

Create the xml layout for the infobar and the tabs. For example:

<?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>

替换TextView的信息栏有自己的布局。请注意,相对布局tab_layout?这将是将由片所占据的空间。按照例如。从这个例子所采取的链接:

Replace the infobar textview with your own layout. Notice the relative layout "tab_layout"? That will be the space that will be occupied by the tabs. Follow the example here. Taken from the example on the link:

/* 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。

Change this: ft.add(android.R.id.content, mFragment, mTag) to this ft.add(R.id.tab_layout, mFragment, mTag). Notice that we used our own layout instead of android.R.id.content.