Tabbar 停止显示对 Xamarin->Laoyuts 中的 Tabbar 文件所做的任何修改
Tabbar stopped showing any modifications made to the Tabbar file in Xamarin->Laoyuts
这里是新的。我需要帮助弄清楚为什么我的 xamarin 项目没有读取我对 Tabbar.xml 文件所做的任何更改。在我决定添加启动画面样式之前,一切都运行良好。它可能是别的东西,但这是我对我的项目所做的唯一重大更改,除非我删除了我不应该删除的内容。无论如何,我也会展示这些变化。我正在考虑制作一个自定义渲染器来避免这种头痛,但我真的很好奇为什么会这样。未选择的色调颜色也默认为白色。我可以尝试在 Tabbar.xml 端更改它,但它不会更新。只有 selectedTabcolor 发生变化,但因为我在 <TabbedPage></TabbedPage>
本身中设置了它。我想要的只是让未选择的选项卡的文本颜色默认为选项卡图标似乎默认的灰色,这就是它过去的样子,并将 selectedTabcolor 和 TabIndicatorColor 设置为相同的颜色,即 #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);
}
}
启动画面
[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"
/>
编辑:根据要求,这里是我的标签栏的图片:
我还从 <TabbedPage>
本身中删除了 SelectedTabColor,并将这些更改添加到 Tabbar.xml,这就是结果。我无法通过 Tabbar 更改文本颜色、指示器颜色或所选颜色。我相信我的 Tabbar.xaml 页面没有被阅读。
您可以在 androd 项目的 Resources/layout/Tabbar.xml
中的 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中设置UnselectedTabColor
或SelectedTabColor
,它将覆盖Tabbar.xml
中的设置。它与启动无关您添加的页面。
如果您的项目已经迁移到 AndroidX,您可以单独安装 Xamarin.AndroidX.AppCompat.Resources
和 Xamarin.Android.Support.Design
nugets。
这里是新的。我需要帮助弄清楚为什么我的 xamarin 项目没有读取我对 Tabbar.xml 文件所做的任何更改。在我决定添加启动画面样式之前,一切都运行良好。它可能是别的东西,但这是我对我的项目所做的唯一重大更改,除非我删除了我不应该删除的内容。无论如何,我也会展示这些变化。我正在考虑制作一个自定义渲染器来避免这种头痛,但我真的很好奇为什么会这样。未选择的色调颜色也默认为白色。我可以尝试在 Tabbar.xml 端更改它,但它不会更新。只有 selectedTabcolor 发生变化,但因为我在 <TabbedPage></TabbedPage>
本身中设置了它。我想要的只是让未选择的选项卡的文本颜色默认为选项卡图标似乎默认的灰色,这就是它过去的样子,并将 selectedTabcolor 和 TabIndicatorColor 设置为相同的颜色,即 #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);
}
}
启动画面
[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"
/>
编辑:根据要求,这里是我的标签栏的图片:
我还从 <TabbedPage>
本身中删除了 SelectedTabColor,并将这些更改添加到 Tabbar.xml,这就是结果。我无法通过 Tabbar 更改文本颜色、指示器颜色或所选颜色。我相信我的 Tabbar.xaml 页面没有被阅读。
您可以在 androd 项目的 Resources/layout/Tabbar.xml
中的 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中设置UnselectedTabColor
或SelectedTabColor
,它将覆盖Tabbar.xml
中的设置。它与启动无关您添加的页面。
如果您的项目已经迁移到 AndroidX,您可以单独安装 Xamarin.AndroidX.AppCompat.Resources
和 Xamarin.Android.Support.Design
nugets。