TabPageIndicator完全失去了它的风格..为什么?

时间:2015-03-20 10:26:54

标签: android android-tabs viewpagerindicator

我在其中创建了一个带有TabPageIndicator的对话框。问题是菜单看起来像TextViews(不是可点击的静态白色文本)而不是预期的标签。

在附件中你可以看到结果:

Image describing the tabs

我做错了什么?我不知道它可能是什么,所以我附上可能有助于理解问题的代码(我也试图完全禁用我的自定义样式,所以我不会因为这个原因发布它)。

主要课程:

public class NotificationsFragment extends DialogFragment {
    private final RpcHandler rpcHandler;

    public NotificationsFragment(){
        rpcHandler = RpcHandler.getInstance();
    }

    @Override
    public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_notifications, null, false);

        TabPageIndicator titles = (TabPageIndicator) root.findViewById(R.id.tabs);
        ViewPager pager = (ViewPager) root.findViewById(R.id.pager);

        final String[] titleNames = new String[]{"All", "Exception", "Warnings", "BadRPC"};

        FragmentStatePagerAdapter adapter = new FragmentStatePagerAdapter(getChildFragmentManager()) {
            @Override
            public String getPageTitle(int position) {
                return titleNames[position];
            }

            @Override
            public int getCount() {
                return titleNames.length;
            }

            @Override
            public Fragment getItem(final int position) {
                return new Fragment(){
                    public ArrayList<NotificationsHandler.NotificationEvent> notifications;

                    @Override
                    public View onCreateView(LayoutInflater _layoutInflater, ViewGroup container,
                            Bundle savedInstanceState) {
                        [...] // useless for this problem

                        return convertView;
                    }
                };
            }
        };
        pager.setAdapter(adapter);
        titles.setViewPager(pager);

        Rect displayRectangle = new Rect();
        Window window = getActivity().getWindow();
        window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);

        root.setMinimumWidth((int) (displayRectangle.width() * 0.7));
        root.setMinimumHeight((int) (displayRectangle.height() * 0.7));
        return root;
    }
}

虽然这是相关的XML:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <com.viewpagerindicator.TabPageIndicator
        android:id="@+id/tabs"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        />
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />

</LinearLayout>

有什么想法吗? :)谢谢!

1 个答案:

答案 0 :(得分:0)

我已经解决了将这些行添加到我的风格中的问题:

<item name="vpiIconPageIndicatorStyle">@style/Widget.IconPageIndicator</item>
<item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
相关问题