微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Tabbar 停止显示对 Xamarin->Laoyuts 中的 Tabbar 文件所做的任何修改

如何解决Tabbar 停止显示对 Xamarin->Laoyuts 中的 Tabbar 文件所做的任何修改

新来的。我需要帮助弄清楚为什么我的 xamarin 项目没有读取我对 Tabbar.xml 文件所做的任何更改。一切正常,直到我决定添加启动画面样式。它可能是别的东西,但这是我对我的项目所做的唯一重大改变,除非我删除了一些我不应该删除的东西。无论如何,我也会展示这些变化。我正在考虑制作一个自定义渲染器来避免这种头痛,但我真的很好奇为什么会发生这种情况。此外,未选择的色调颜色认为白色。我可以尝试在 Tabbar.xml 端更改它,但它不会更新。只有 selectedTabcolor 更改,但因为我在 <TabbedPage></TabbedPage> 本身中设置了它。我想要的只是让未选择的选项卡的文本颜色认为选项卡图标似乎认的灰色,这就是以前的样子,并将 selectedTabcolor 和 TabIndicatorColor 设置为与 #008000 相同的颜色。 主活动

[Activity(Label = "Weather App",Icon = "@mipmap/icon",Theme = "@style/MainTheme",ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
            base.SetTheme(Resource.Style.MainTheme);

            base.OnCreate(savedInstanceState);
            CrossCurrentActivity.Current.Init(this,savedInstanceState);
            Rg.Plugins.Popup.Popup.Init(this);
            Xamarin.Essentials.Platform.Init(this,savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this,savedInstanceState);
           
            LoadApplication(new App());
        }

        public override void OnRequestPermissionsResult(int requestCode,string[] permissions,[GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode,permissions,grantResults);

            base.OnRequestPermissionsResult(requestCode,grantResults);
        }

        
}

启动画面

[Activity(Label = "Weather App",Theme ="@style/SplashTheme",MainLauncher = true)]
    public class SplashActivity : AppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            var intent = new Intent(this,typeof(MainActivity));
            StartActivity(intent);
            Finish();
        }
 }

Styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MainTheme" parent="MainTheme.Base">
       <item name="colorPrimary">#efefef</item>
        <!-- colorPrimaryDark is used for the status bar -->
        <item name="colorPrimaryDark">#008000</item>
        <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
        <item name="colorAccent">#019501</item>
    </style>
    <!-- SPLASH SCREEN -->
     <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_screen</item>
    </style>
</resources>

Tabbar.xml

<android.support.design.widget.TabLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:tabGravity="fill"
    app:tabMode="fixed"
    app:tabTextColor="@android:color/black"
    app:tabIndicatorHeight="2dp"
    app:tabIndicatorColor="#008000"
    />

编辑:根据请求,这里是我的标签栏外观的图像:

enter image description here

我还从 <TabbedPage> 本身中删除了 SelectedTabColor 并将这些更改添加到 Tabbar.xml 中,这就是结果。我无法通过 Tabbar 获取文本颜色、指示器颜色或所选颜色。我相信我的 Tabbar.xaml 页面没有被读取。

解决方法

您可以在 androd 项目的 Tabbar.xml 中的 Resources/layout/Tabbar.xml 中定义文本颜色。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:tabGravity="fill"
    app:tabMode="fixed" 
    app:tabTextColor="@android:color/black"   //unselect text color
    app:tabIndicatorHeight="2dp"
    app:tabSelectedTextColor="#008000"
    app:tabIndicatorColor="#008000"
/>

如果您在 tabbedpage.xaml 中设置了 UnselectedTabColorSelectedTabColor,它将覆盖 Tabbar.xml 中的设置。它与您添加的启动页面无关。

如果您的项目已迁移到 AndroidX,您可以分别安装 Xamarin.AndroidX.AppCompat.ResourcesXamarin.Android.Support.Design nuget。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。