Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 棒棒糖上看不到标签_Android - Fatal编程技术网

Android 棒棒糖上看不到标签

Android 棒棒糖上看不到标签,android,Android,我在一个包含导航抽屉的活动中的片段中创建了一个片段TabHost。这些标签在KitKat和jelly beans设备上可见,但在棒棒糖设备上不可见 片段: public static class PlaceholderFragment extends Fragment { private FragmentTabHost mTabHost; private DisplayMetrics metrics; private int height; int textsi

我在一个包含导航抽屉的活动中的片段中创建了一个片段TabHost。这些标签在KitKat和jelly beans设备上可见,但在棒棒糖设备上不可见

片段:

public static class PlaceholderFragment extends Fragment {

    private FragmentTabHost mTabHost;
    private DisplayMetrics metrics;
    private int height;
    int textsize;

    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    //private static final String ARG_SECTION_NUMBER = "section_number";

    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    public static PlaceholderFragment newInstance(int sectionNumber) {
        PlaceholderFragment fragment = new PlaceholderFragment();
        /*Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);*/
        return fragment;
    }

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        setHasOptionsMenu(true);
        View rootView = inflater.inflate(R.layout.fragment_primary_option, container, false);
        ButterKnife.inject(this,rootView);
        metrics=new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
        switch(metrics.densityDpi)
        {
            case DisplayMetrics.DENSITY_LOW:
                height=30;
                textsize=10;
                break;
            case DisplayMetrics.DENSITY_MEDIUM:
                height=70;
                textsize=40;
                break;
            case DisplayMetrics.DENSITY_HIGH:
                height=100;
                textsize=60;
                break;
            case DisplayMetrics.DENSITY_XHIGH:
                height=100;
                textsize=60;

        }
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.weight=1;


        Log.e("TAG","before tabhost");
        mTabHost = (FragmentTabHost) rootView.findViewById(android.R.id.tabhost);
        // Create the tabs in main_fragment.xml
        mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.tabcontent);

        // Create Tab1 with a custom image in res folder
        mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Jobs"),
                JobsFragment.class, null);



        mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Tournaments"),
                TournamentFragment .class, null);


        mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Events"),
                EventsFragment.class, null);

        Typeface typeface=Typeface.createFromAsset(getActivity().getAssets(),"fonts/OpenSans-Semibold.ttf");

        Log.e("TAG","after tabhost");


        for(int i=0;i<3;i++) {
            mTabHost.getTabWidget().getChildAt(i).setLayoutParams(params);
            mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_indicator_ab_example);
            final TextView tab_text = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
            tab_text.setTextColor(Color.parseColor("#646464"));
            tab_text.setTypeface(typeface);
            tab_text.setAllCaps(false);
            tab_text.setTextSize(16f);
            tab_text.setPadding(0,15,0,20);
        }
        return rootView;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        /*((Primary_Option) activity).onSectionAttached(
                getArguments().getInt(ARG_SECTION_NUMBER));*/
    }
}
公共静态类占位符片段扩展片段{
私有碎片选项卡主机mTabHost;
私有显示度量;
私人内部高度;
int文本大小;
/**
*表示此文件节号的片段参数
*碎片。
*/
//私有静态最终字符串ARG\u SECTION\u NUMBER=“SECTION\u NUMBER”;
/**
*返回给定节的此片段的新实例
*号码。
*/
公共静态占位符片段newInstance(int sectionNumber){
占位符片段=新占位符片段();
/*Bundle args=新Bundle();
参数Putin(参数段号,段号);
fragment.setArguments(args)*/
返回片段;
}
公共占位符片段(){
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
设置选项菜单(真);
视图根视图=充气机。充气(R.layout.fragment\u primary\u选项,容器,false);
ButterKnife.injection(这个,rootView);
metrics=新的DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(度量);
交换机(metrics.densityDpi)
{
案例DisplayMetrics.DENSITY\u低:
高度=30;
textsize=10;
打破
case DisplayMetrics.DENSITY\u介质:
高度=70;
textsize=40;
打破
案例DisplayMetrics.DENSITY\u高:
高度=100;
textsize=60;
打破
case DisplayMetrics.DENSITY\u XHIGH:
高度=100;
textsize=60;
}
LinearLayout.LayoutParams params=新的LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_内容,ViewGroup.LayoutParams.WRAP_内容);
参数重量=1;
Log.e(“标签”,“在tabhost之前”);
mTabHost=(FragmentTabHost)rootView.findviewbyd(android.R.id.tabhost);
//在main_fragment.xml中创建选项卡
mTabHost.setup(getActivity(),getChildFragmentManager(),R.id.tabcontent);
//在res文件夹中创建带有自定义图像的Tab1
mTabHost.addTab(mTabHost.newTabSpec(“tab1”).setIndicator(“作业”),
JobsFragment.class,null);
mTabHost.addTab(mTabHost.newTabSpec(“tab2”).setIndicator(“锦标赛”),
TournamentFragment.class,空);
mTabHost.addTab(mTabHost.newTabSpec(“tab3”).setIndicator(“事件”),
EventsFragment.class,null);
Typeface Typeface=Typeface.createFromAsset(getActivity().getAssets(),“fonts/OpenSans Semibold.ttf”);
Log.e(“TAG”,“tabhost之后”);

对于(int i=0;我能发布你的代码或布局吗?你现在可以检查代码了。这个片段包含片段tabhost。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="darkhorsesports.getsporty.Primary_Option$PlaceholderFragment"
>
<android.support.v4.app.FragmentTabHost
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:paddingBottom="10dp"
    >
</android.support.v4.app.FragmentTabHost>
<FrameLayout
    android:id="@+id/tabcontent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
</RelativeLayout>