Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

xamarin.android - Tabbar stopped showing any modifications made to the Tabbar file in Xamarin->Laoyuts

new here. I need help figuring out why my xamarin project is not reading any of the changes I make to the Tabbar.xml file. Everything was working fine until I decided to add a splash screen style. It could have been something else but that is the only major change I have done to my project, unless I deleted something i wasn't supposed to. Regardless I will be showing those changes as well. I was thinking of just making a custom renderer to avoid this headache, but not I really am curious why this is occurring. Also the unselected tint color has defaulted to white. I can try to change that on the Tabbar.xml side but it does not update. Only the selectedTabcolor changes but because I set that in the <TabbedPage></TabbedPage> itself. All I want is to have the Text color of the unselected tabs to default the grey that the tab icons seem to defult to, that's how it used to be, and set the selectedTabcolor and TabIndicatorColor to the same color which is #008000. MainActivity

[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, permissions, grantResults);
        }

        
}

SplashScreen

[Activity(Label = "Weather App", Icon = "@mipmap/icon", 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"
    />

EDIT: As request here is an image of how my tabbar looks like: enter image description here

I also removed the SelectedTabColor from the <TabbedPage> itself and added on those changes to the Tabbar.xml and this is the result. I can't get the text color, nor the indicator color nor the selected color to change through the Tabbar. I believe my Tabbar.xaml page is just not being read.

question from:https://stackoverflow.com/questions/65876918/tabbar-stopped-showing-any-modifications-made-to-the-tabbar-file-in-xamarin-lao

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could define the text color in your Tabbar.xml in the Resources/layout/Tabbar.xml of the androd project.

<?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"
/>

and if you set the UnselectedTabColor or SelectedTabColor in your tabbedpage.xaml,It will overrides the settings in the Tabbar.xml.It has nothing to do with the startup page you added.

If your project has migrated to AndroidX,you could install Xamarin.AndroidX.AppCompat.Resources and Xamarin.Android.Support.Design nugets separately.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...