#c# #xml #xamarin.android
#c# #xml #xamarin.android
Вопрос:
Итак, я перепробовал почти все ответы, которые я нашел в stackoverflow, но ни один из них не сработал. Я получаю эту ошибку каждый раз, когда пытаюсь SetContentView(Resource.Layout.activity_main);
Android.Число просмотров.Исключение InflateException: ‘Строка двоичного XML-файла №1 в com.abcbraga.abcfichaobras:layout/activitymain: строка двоичного XML-файла №1 в com.abcbraga.abcfichaobras:layout /activitymain: ошибка раздувания класса com.google.android.material.navigation.NavigationView’
activity_main.xml выглядит примерно так:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@ id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@ id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
но даже здесь я получаю ошибку в конструкторе
ошибка
Я также пытался удалить headerLayout и menu, но безрезультатно
Заголовок
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:contentDescription="Image"
android:id="@ id/header_imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
android:id="@ id/header_Email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@ id/header_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
setContentView
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar")]
public class MainActivity : AppCompatActivity, NavigationView.IOnNavigationItemSelectedListener
{
public FirebaseRemoteConfig firebaseRemoteConfig;
public FloatingActionButton fab;
public FirebaseFirestore db;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
Android.Support.V7.Widget.Toolbar toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
fab.Click = FabOnClick;
//Init Firestore
db = GetDataBase();
firebaseRemoteConfig = FirebaseRemoteConfig.Instance;
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().Build();
firebaseRemoteConfig.SetConfigSettings(configSettings);
DrawerLayout drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);
drawer.AddDrawerListener(toggle);
toggle.SyncState();
NavigationView navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
navigationView.SetNavigationItemSelectedListener(this);
}
Комментарии:
1. Можете ли вы указать контекст, в котором вы вызываете
SetContentView(...)
?2. Отредактировал мой вопрос
3. Я запускаю с вашими кодами, но не смог воспроизвести проблему, она работает хорошо. Не могли бы вы показать свой
app_bar_main
xml?4.
app:itemTextColor="#79847A"
Я предполагаю, что текст не имел цвета, поэтому он не мог его отобразить, и он разбился.