标签分配器没有显示在ICS [英] Tab Dividers Not Showing In ICS

查看:71
本文介绍了标签分配器没有显示在ICS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有.setDividerDrawable一个问题()只工作在版本比冰淇淋三明治更低。当我运行模拟器上的标签显示完美,但没有护栏。当模拟更低版本的Andr​​oid是没有问题的,分频器显示。

I have a problem with .setDividerDrawable() only working in versions lower than Ice Cream Sandwich. When I run the emulator the tabs show perfectly, but no divider. When emulating lower versions of Android there is no problem, the dividers show.

我用这$ C $下创建TabHost。我有什么,那就是让ICS畏缩不知道。

I am using this code for creating the TabHost. I have no clue on what it is that makes ICS flinch.

manifest.xml的

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sbl.mytabapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:debuggable="true" >
        <activity
            android:name=".MyTabApp"
            android:label="@string/app_name"
            android:theme="@style/MyTabAppTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".Page1"></activity>
        <activity android:name=".Page2"></activity>
        <activity android:name=".Page3"></activity>
    </application>

</manifest>

MyTabApp.java(R.drawable.divider)指的是这一形象:这是只是1px的宽.jpg文件。上ICS没有示出。

MyTabApp.java (R.drawable.divider) refers to this image: which is just a 1px wide .jpg file. On ICS it is not shown.

public class MyTabApp extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;

        tabHost.getTabWidget().setDividerDrawable(R.drawable.divider);

        intent = new Intent().setClass(this, Page1.class);
        spec = tabHost.newTabSpec("page1").setIndicator(getLayoutInflater().inflate(R.layout.tab1, null))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Page2.class);
        spec = tabHost.newTabSpec("page2").setIndicator(getLayoutInflater().inflate(R.layout.tab2, null))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Page3.class);
        spec = tabHost.newTabSpec("page3").setIndicator(getLayoutInflater().inflate(R.layout.tab3, null))
                      .setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(0);

    } 
}

main.xml中

main.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
</TabHost>

style.xml

style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

 <style name="MyTabAppTheme" parent="android:style/Theme"> 
    <item name="android:windowNoTitle">true</item>
 </style> 


 <style name="tablayout" parent="android:style/Theme">
     <item name="android:layout_width">match_parent</item>
     <item name="android:layout_height">match_parent</item>
     <item name="android:height">48dp</item>
     <item name="android:gravity">center</item>
     <item name="android:textColor">@color/font</item>
     <item name="android:background">@drawable/tabselector</item>
 </style>

 <style name="contentlayout" parent="android:style/Theme">
     <item name="android:layout_width">match_parent</item>
     <item name="android:layout_height">match_parent</item>
     <item name="android:textColor">@color/font</item>
     <item name="android:background">@color/background</item>
 </style>
</resources>

tab1.xml,tab2.xml,tab3.xml均含有相同的风格。这是标签1:

tab1.xml, tab2.xml, tab3.xml all contains the same reference style. This is tab 1:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/tab1"
  style="@style/tablayout" />

tabselector.xml的标签绘制背景是9patch背景图片。

tabselector.xml The tab drawable backgrounds are 9patch background images.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/normal" />
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/selected" />

    <!-- Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/normal_focused" />
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/selected_focused" />

    <!-- Pressed -->
    <item android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/normal_pressed" />
    <item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/selected_pressed" />
</selector> 

它的外观:该选项卡背景是9patch背景图像

How it looks: The tab backgrounds are 9patch background images.

推荐答案

我有同样的问题,我终于结束了手动添加分隔符。在标签之间添加ImageView的。

I had the same problem, I finally ended up adding the separators manually. Adding ImageView between the tabs..

public class MyTabApp extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageView divider = new ImageView(this);
        divider.setImageResource(R.drawable.tab_seperator);

        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;

        intent = new Intent().setClass(this, Page1.class);
        spec = tabHost.newTabSpec("page1").setIndicator(getLayoutInflater().inflate(R.layout.tab1, null))
                  .setContent(intent);
        tabHost.addTab(spec);

        tabHost.getTabWidget().addView(divider, LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);

        intent = new Intent().setClass(this, Page2.class);
        spec = tabHost.newTabSpec("page2").setIndicator(getLayoutInflater().inflate(R.layout.tab2, null))
                  .setContent(intent);
        tabHost.addTab(spec);
    } 
}

这篇关于标签分配器没有显示在ICS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆