.NET MAUI getting error on Android : Error inflating class android.widget.TextView

Paolo Levati 0 Reputation points
2025-01-14T11:46:50.05+00:00

In .NET MAUI getting below error only for android when i try to show snackbar (maui toolkit) :

Java.Lang.RuntimeException

Binary XML file line #26 in it.test.App:layout/design_layout_snackbar_include: Binary XML file line #26 in it.test.App:layout/design_layout_snackbar_include: Error inflating class android.widget.TextView.

C# :

var snackBarOptions = new SnackbarOptions

{

BackgroundColor = Color.FromArgb("#f84b51"),

CornerRadius = 4,

TextColor = Colors.White,

ActionButtonTextColor = Colors.White 
};

MainThread.BeginInvokeOnMainThread(async () =>

{


await Shell.Current.DisplaySnackbar($"Error message", visualOptions: snackBarOptions, duration: TimeSpan.FromSeconds(10));
});

I am using .NET 8.

Android version : 11,12

I have now discovered a second exception related to the first one :
UnsupportedOperationException : Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1} And this is the first part of the XML file (design_layout_snackbar_include) indicating in the first exception that i have found under obj folder of the project :



<?xml version="1.0" encoding="utf-8"?>

<!--

   Copyright (C) 2015 The Android Open Source Project

  

   Licensed under the Apache License, Version 2.0 (the "License");

   you may not use this file except in compliance with the License.

   You may obtain a copy of the License at

  

[http://www.apache.org/licenses/LICENSE-2.0]()
``````  Unless required by applicable law or agreed to in writing, software

   distributed under the License is distributed on an "AS IS" BASIS,

   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  See the License for the specific language governing permissions and

  limitations under the License.

-->

<view


xmlns:android="http://schemas.android.com/apk/res/android"

class="com.google.android.material.snackbar.SnackbarContentLayout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="bottom"

android:theme="@style/ThemeOverlay.AppCompat.Dark">
<TextView   


  android:id="@+id/snackbar_text"

  android:layout_width="wrap_content"

  android:layout_height="wrap_content"

  android:layout_weight="1"

  android:layout_gravity="center_vertical|left|start"

  android:paddingTop="@dimen/design_snackbar_padding_vertical"

  android:paddingBottom="@dimen/design_snackbar_padding_vertical"

  android:paddingLeft="@dimen/design_snackbar_padding_horizontal"

  android:paddingRight="@dimen/design_snackbar_padding_horizontal"

  android:ellipsize="end"

  android:maxLines="@integer/design_snackbar_text_max_lines"

  android:textAlignment="viewStart"

  android:textAppearance="@style/TextAppearance.Design.Snackbar.Message"/>

Thanks

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,814 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.