作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在向我的应用程序添加一个 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>
android:theme="@style/AppTheme"
最佳答案
You need to use a Theme.AppCompat theme (or descendant) with this activity.
Activity
应用范围中的主题 Manifest.xml
(所有事件)Theme
Activity
中的属性. Activity
应用范围中的主题
Manifest.xml
(所有事件):
<application
android:label="@string/app_name"
android:icon="@drawable/Icon"
android:theme="@style/AppTheme">
</application>
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/
我是一名优秀的程序员,十分优秀!