0

在此处输入图像描述

我已经为 android 制作了一个应用程序,其Xamarin形式为VS2015. 我已添加TabbedPage,但我的TabbedPage's操作栏有问题。

如果 tabbedPage 有很多ContentPage,标题文本不是1 line,并且我不能更改选项卡的height, width, color(字体,背景)和scrollable选项卡。

我知道问题是theme,但我不知道如何自定义主题。

下面是我的主题:

    <?xml version="1.0" encoding="UTF-8"?>
    <resources>
        <style name="MyTheme" parent="MyTheme.Base">
        </style>
        <!-- Base theme applied no matter what API -->
        <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
            <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
            <item name="windowNoTitle">true</item>
            <!--We will be using the toolbar so no need to show ActionBar-->
            <item name="windowActionBar">false</item>
            <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
            <!-- colorPrimary is used for the default action bar background -->
            <item name="colorPrimary">#2196F3</item>
            <!-- colorPrimaryDark is used for the status bar -->
            <item name="colorPrimaryDark">#1976D2</item>
            <!-- colorAccent is used as the default value for colorControlActivated
             which is used to tint widgets -->
            <item name="colorAccent">#FF4081</item>
            <!-- You can also set colorControlNormal, colorControlActivated
             colorControlHighlight and colorSwitchThumbNormal. -->
            <item name="windowActionModeOverlay">true</item>
            <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
        </style>
        <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
            <item name="colorAccent">#FF4081</item>
        </style>
    </resources>

现在,我的应用需要AppCompact主题,所以我不知道如何修复它。

4

2 回答 2

1

尝试使用"scrollable"Tab 模式。

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="scrollable"
        style="@style/MyCustomTabLayout" />

在这里,我使用了自定义TabLayout样式。下面是MyCustomTabLayout风格。将此样式定义到您的values/styles.xml文件中。

值/样式.xml

<!-- TabLayout Style -->
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabIndicatorColor">#FFFFFF</item>
    <item name="tabIndicatorHeight">3dp</item>
    <item name="tabBackground">?attr/selectableItemBackground</item>
    <item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item>
    <item name="tabSelectedTextColor">#FFFFFF</item>
</style>

希望这会有所帮助~

于 2017-04-13T06:07:02.900 回答
0

如果你的风格主题是 AppCompact(见清单文件),那么你的类应该是扩展 AppCompactActivity 类,否则它会抛出错误。我认为 viewPager 使用起来很舒服。

看看这段代码我如何在 ViewPager 中更改 textcolor、height、tabindicator 颜色

<android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#499b97"
            app:tabGravity="fill"
            app:tabIndicatorColor="#cfc31b"
            app:tabIndicatorHeight="6dp"
            app:tabMode="fixed" />
    </android.support.design.widget.AppBarLayout>

<style name="MyTrasparent" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:background">@android:color/transparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:colorBackground">@android:color/transparent</item>
    <item name="android:windowBackground">@color/soloColor</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation</item>

于 2017-04-13T06:11:47.540 回答