【问题标题】:FragmentTabHost tabs transparent when they should be opaqueFragmentTabHost 选项卡在应该不透明时是透明的
【发布时间】:2015-04-13 01:38:01
【问题描述】:

我最近将我的应用从所有活动更改为所有片段。作为更改的一部分,我开始使用行为异常的片段选项卡主机。

由于某种原因,我的选项卡是透明的,并在选项卡按钮下方显示内容,但所有教程都将它们显示为不透明,下方有内容。我没有做任何特别的事情,需要弄清楚如何使它们按预期工作。应用程序“风格”是 Theme.AppCompat.Light 如果这有什么不同的话。

这是它当前在设备上的外观:https://dl.dropboxusercontent.com/u/70446113/MLP/2015-04-13_10-55-31.png

这是主机片段

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);

    rootView = inflater.inflate(R.layout.fragment_search, container, false);

    mTabHost = (FragmentTabHost) rootView.findViewById(android.R.id.tabhost);
    mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);

    mTabHost.addTab(mTabHost.newTabSpec(basicTag).setIndicator("Basic"), BasicSearchFragment.class, null);
    mTabHost.addTab(mTabHost.newTabSpec(advancedTag).setIndicator("Advanced"), AdvancedSearchFragment.class, null);

    return rootView;
}

片段布局。内容布局是包含许多按钮的线性布局。

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="8dp" >

    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >
        </LinearLayout>
    </android.support.v4.app.FragmentTabHost>

</LinearLayout>

任何帮助将不胜感激

【问题讨论】:

    标签: android android-fragments fragment-tab-host


    【解决方案1】:

    您需要在标签主机中添加 TabWidget。查看我在您的布局中所做的更改:

    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <TabWidget
                android:id="@android:id/tabs"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp" />
    
            <FrameLayout
                android:id="@+id/realtabcontent"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />
        </LinearLayout>
    </android.support.v4.app.FragmentTabHost>
    

    更多参考请看Question

    希望它会有所帮助。

    【讨论】:

      猜你喜欢
      • 2021-02-06
      • 2014-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-11
      • 2014-01-28
      • 1970-01-01
      • 2011-06-19
      相关资源
      最近更新 更多