gpt4 book ai didi

xamarin.android - "You need to use a Theme.AppCompat theme (or descendant) with this activity."Xamarin

转载 作者:行者123 更新时间:2023-12-01 00:21:52 26 4
gpt4 key购买 nike

我正在向我的应用程序添加一个 float 操作按钮,我有一个 Material 设计主题并将其设置到 Android list 中,我已经将 AppCompatActivity 继承设置为 MainActivity 但是如果我运行我的应用程序我有一个异常(exception)说“你需要在此事件中使用 Theme.AppCompat 主题(或后代)。”

这是我的主要事件:

using System;
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.Design.Widget;
using Android.Support.V4.View;
using Android.Support.V7.App;
using Android.Views;

namespace M_v1
{
[Activity(Label = "Muzzillo_v1", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
Android.Support.V7.Widget.Toolbar toolbar;
private FloatingActionButton fabMain;
private View bgFabMenu;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);

TabLayout tabLayout = (TabLayout)FindViewById(Resource.Id.tablayout_navigation);

ViewPager viewPager = (ViewPager)FindViewById(Resource.Id.pager);
SetupviewPager(viewPager);

fabMain = FindViewById<FloatingActionButton>(Resource.Id.fab);
bgFabMenu = FindViewById<View>(Resource.Id.bg_fab_menu);

fabMain.Click += FabMain_Click;

tabLayout.SetupWithViewPager(viewPager);

toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);

toolbar.Title = "App_v1";
}

private void FabMain_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}

private void SetupviewPager(ViewPager viewPager)
{
viewPager.OffscreenPageLimit = 2;

PageAdapter adapter = new PageAdapter(SupportFragmentManager);
adapter.AddFragment(new Fragment1(), "One");
adapter.AddFragment(new Fragment2(), "Two");

viewPager.Adapter = adapter;
}

}
}

这是我的主题:
<resources>
<style name = "AppTheme.Base" parent = "Theme.AppCompat.Light.NoActionBar">
<item name ="colorPrimary">@color/primary</item>
<item name ="colorPrimaryDark">@color/primaryDark</item>
<item name="android:windowBackground">@color/window_background</item>
<item name="windowActionModeOverlay">true</item>
</style>

<style name="AppTheme" parent="AppTheme.Base">
</style>
</resources>

安卓 list :
android:theme="@style/AppTheme"

最佳答案

You need to use a Theme.AppCompat theme (or descendant) with this activity.



有两种解决方案可以解决您的问题:
  • 套装Activity应用范围中的主题 Manifest.xml (所有事件)
  • 或添加 Theme Activity 中的属性.

  • 1. Theming an Application

    套装 Activity应用范围中的主题 Manifest.xml (所有事件):
    <application 
    android:label="@string/app_name"
    android:icon="@drawable/Icon"
    android:theme="@style/AppTheme">
    </application>

    2. Theming an Activity

    在 Xamarin.Android 中, 建议添加Activity主题作为属性 .您可以阅读文档 Material Theme :

    To theme an activity, you add a Theme setting to the [Activity] attribute above your activity declaration and assign Theme to the Material Theme flavor that you want to use. The following example themes an activity with Theme.Material.Light:



    例如 :
    [Activity(Label = "Muzzillo_v1", MainLauncher = true, Theme = "@style/AppTheme")]
    public class MainActivity : AppCompatActivity

    关于xamarin.android - "You need to use a Theme.AppCompat theme (or descendant) with this activity."Xamarin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48174193/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com