Android TabHost文字对齐

时间:2017-01-06 18:03:39

标签: android android-tabhost

我有一个非常简单的问题 - 我的TabHost上的标签文字没有正确对齐。

enter image description here

注意“设置”低于其余部分。以前这个(非常老的)应用程序的目标是API 9,标签显示文本和图标,一切都很好。我最近更新了目标并改变了外观(这很好)并且文本没有正确对齐。

主要布局:

<?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="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:paddingBottom="0dp"/>
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</TabHost>

主要活动:

public class MainActivity extends TabActivity {

// ...snip...

final TabHost host = getTabHost();

        host.addTab(host.newTabSpec(TabIndex.HOME.name())
                .setIndicator(TabIndex.HOME.text, AppCompatResources.getDrawable(this, R.drawable.home_icon) )
                .setContent(new Intent(this, MainMenu.class)));
        host.addTab(host
                .newTabSpec(TabIndex.SEARCH.name())
                .setIndicator(TabIndex.SEARCH.text, AppCompatResources.getDrawable(this, R.drawable.find_icon))
                .setContent(m_propGroupIntent));
        host.addTab(host
                .newTabSpec(TabIndex.SETTINGS.name())
                .setIndicator(TabIndex.SETTINGS.text, AppCompatResources.getDrawable(this, R.drawable.settings))
                .setContent(new Intent(this, SettingsScreen.class)));
        host.addTab(host
                .newTabSpec(TabIndex.CALL.name())
                .setIndicator(TabIndex.CALL.text,
                        AppCompatResources.getDrawable(this, R.drawable.phone_icon))
                .setContent(new Intent(this, ContactUs.class)));

构建文件摘录:

compileSdkVersion = 25
buildToolsVersion = "23.0.3"
defaultConfig {
        minSdkVersion 14
        targetSdkVersion 25

        testInstrumentationRunner "com.redshedtechnology.common.MultiDexAndroidJUnitRunner"
        testFunctionalTest true

        multiDexEnabled true
    }

我尝试更改文字大小:

<item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
    </style>
    <style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">
        <item name="android:textAppearance">@style/CustomTabWidgetText</item>
    </style>
    <style name="CustomTabWidgetText"
        parent="@android:style/TextAppearance.Widget.TabWidget">
        <item name="android:textSize">12sp</item>
    </style>

这解决了对齐问题,但完全搞砸了标签显示。

enter image description here

编辑:这里的最小和完整示例:https://dl.dropboxusercontent.com/u/76707225/MyApplication.zip

这不使用自定义标签布局,而是使用默认设置。它完全展示了我的应用程序的行为,并且几乎没有任何代码或布局,非常简单。如果您想尝试一下,它就是一个压缩的Android Studio项目。

0 个答案:

没有答案