The following XML file will be inflated and I don't know why I'm getting an error. Here is the XML file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/overseas_broker_sell_avatar"
android:layout_width="108dp"
android:layout_height="108dp"
android:layout_marginTop="15dp"
android:contentDescription="#null"
app:layout_constraintStart_toStartOf="parent"
fresco:actualImageScaleType="centerCrop" />
<TextView
android:id="#+id/overseas_broker_sell_company_title"
style="#style/overseasAgentTitle"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:text="海外代理公司"
app:layout_constraintStart_toEndOf="#+id/overseas_broker_sell_avatar"
app:layout_constraintTop_toTopOf="#+id/overseas_broker_sell_avatar" />
<TextView
android:id="#+id/overseas_broker_sell_company_value"
style="#style/overseasAgentDescribe"
android:layout_width="0dp"
android:layout_height="15dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/overseas_broker_sell_company_title"
app:layout_constraintTop_toBottomOf="#+id/overseas_broker_sell_company_title"
tools:text="Philippine Boracay Blue Water111111111" />
<TextView
android:id="#+id/overseas_broker_sell_presenter_title"
style="#style/overseasAgentTitle"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:text="海外置业代表"
app:layout_constraintStart_toStartOf="#+id/overseas_broker_sell_company_value"
app:layout_constraintTop_toBottomOf="#+id/overseas_broker_sell_company_value" />
<TextView
android:id="#+id/overseas_broker_sell_presenter_value"
style="#style/overseasAgentDescribe"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:width="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/overseas_broker_sell_presenter_title"
app:layout_constraintTop_toBottomOf="#+id/overseas_broker_sell_presenter_title"
tools:text="AddressAddressAddressAddressAddressAddress" />
<TextView
android:id="#+id/overseas_broker_sell_phone_title"
style="#style/overseasAgentTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="海外代理电话"
app:layout_constraintStart_toStartOf="#+id/overseas_broker_sell_presenter_value"
app:layout_constraintTop_toBottomOf="#+id/overseas_broker_sell_presenter_value" />
<TextView
android:id="#+id/overseas_broker_sell_phone_value"
style="#style/overseasAgentDescribe"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/overseas_broker_sell_phone_title"
app:layout_constraintTop_toBottomOf="#+id/overseas_broker_sell_phone_title"
tools:text="+39 714809471480947007148094700700" />
</android.support.constraint.ConstraintLayout>
Here is the logcat error.
line #31: You must supply a layout_width attribute.
Caused by: java.lang.UnsupportedOperationException: Binary XML file line #31: You must supply a layout_width attribute.
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:767)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:7245)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7427)
at android.support.constraint.ConstraintLayout$LayoutParams.<init>(ConstraintLayout.java:2102)
at android.support.constraint.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:1536)
at android.support.constraint.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:449)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:860)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
I am sure that it is this constraintLayout that's causing the problem, because #31 the line number indicated in the error is exactly the line where this textView layout_width is declared; the textView layout_width is there, so what is it complaining about? is there some other reason for constrainLayout ?
Thanks in advance!
do this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="expandableItemStyle">#style/ExpandableItemStyle</item>
</style>
<style name="ExpandableItemStyle">
<item name="android:layout_height">#dimen/item_size</item>
<item name="android:layout_width">#dimen/item_size</item>
<item name="android:background">#drawable/bg_item_with_title</item>
<item name="android:layout_margin">#dimen/item_margin</item>
<item name="android:textColor">#color/gray</item>
<item name="android:textSize">#dimen/item_text_size</item>
</style>
it helps you
Related
Images of files to which I made changes after creating the project
image of themes.xml
image of colors.xml
Image of error
image of AndroidManifest.xml
Code from my activity_main.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="#drawable/ic_bg"
tools:context=".MainActivity">
<TextView
android:id="#+id/tv_app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="25sp"
android:gravity="center"
android:text="QuizBuzz"/>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="8dp"
app:cardElevation="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#363A43"
android:textSize="16sp"
android:text="Welcome"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#7A8089"
android:textSize="18sp"
android:text="Please enter your name"
/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<androidx.appcompat.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#363A43"
android:textColorHint="#7A8089"
android:hint="Name"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="#color/purple_500"
android:text="Start">
</Button>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
Problem
When I am clicking the run button, I m getting an error (Image of error -from the 1st list)
I am new to android development. So I cannot understand what is exactly happening. Please help me pinpoint the problem.
if you need anything more please let me know. if you can help me with some online resources I will be grateful.
If you're using Jetpack Compose, then just remove the old themes files and add a single one that needs this content:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.YourProject" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">#color/purple_700</item>
</style>
</resources>
And to set the theme also in AndroidManifest file.
Try this:
Add these missing colors to your colors.xml file:
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/black</item>
<item name="colorSecondaryVariant">#color/teal_200</item>
<item name="colorOnSecondary">#color/black</item>
I'm using a BottomSheetDialogFragment however when I show it, part of it is being cut off at the bottom.
Why isn't it fully inflating and how can I fix this?
Heres the full layout and usage:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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="wrap_content">
<TextView
android:id="#+id/fragplaces_app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="12dp"
android:paddingTop="16dp"
android:paddingEnd="12dp"
android:paddingBottom="16dp"
android:text="test"
android:textColor="#color/colorWhite"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
android:background="#drawable/background_top_round_corners_blue"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/fragnearme_recycler"
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="#color/backgroundColor"
android:paddingBottom="8dp"
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="#+id/fragplaces_app_name"
app:layout_constraintBottom_toTopOf="#+id/send_msg_layout"/>
<RelativeLayout
android:id="#+id/send_msg_layout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/backgroundColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:paddingBottom="8dp">
<ImageView
android:id="#+id/btn_emoji"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:srcCompat="#drawable/ic_grey_smiley_24dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"/>
<EditText
android:id="#+id/challengeroom_et_sendmessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="#id/btn_emoji"
android:background="#drawable/background_chat_send_message"
android:gravity="center_vertical"
android:hint="Type a message"
android:inputType="text"
android:maxLines="1"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:textColorHint="#color/defaultTextColor"
android:textSize="14sp" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Usage:
BottomSheetDialogFragment chatFragment = new ChatFragment();
chatFragment.show(getSupportFragmentManager(), Constants.FRAGMENT_CHAT);
I've tried changing the parent constraint layout height to match_parent and have also tried setting it to a defined height like 500dp, however it still doesn't work.
Adding <item name="behavior_peekHeight">500dp</item> in my BottomSheetDialog's style fixed the issue.
<style name="BottomSheetRoundedCorners" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">#drawable/background_top_round_corners</item>
<item name="behavior_peekHeight">500dp</item>
</style>
<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">#style/BottomSheetRoundedCorners</item>
<item name="behavior_draggable">false</item>
</style>
and using it in my main app theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="bottomSheetDialogTheme">#style/AppBottomSheetDialogTheme</item>
</style>
Credits to this answer:
https://stackoverflow.com/a/35720641/11110509
The layout in a full screen dialog is not rendered properly.
This is my dialog code:
val mDialogView = LayoutInflater.from(this).inflate(R.layout.alertdialog_info, null)
val mBuilder = AlertDialog.Builder(this, R.style.FullScreenDialog)
.setView(mDialogView)
val mAlertDialog = mBuilder.show()
mDialogView.titleTv.text = getString(R.string.title)
mDialogView.descriptionTv.text = getString(R.string.description)
mAlertDialog.show()
in style.xml this is my FullScreenDialog:
<style name="FullScreenDialog" parent="android:Theme.Dialog">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:windowBackground">#color/md_white_1000</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">false</item>
</style>
And this is my layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:paddingTop="16dp"
android:gravity="bottom"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/md_white_1000">
<ImageView
android:id="#+id/iconIv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:src="#drawable/ic_success"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="#id/titleTv" />
<TextView
android:id="#+id/titleTv"
style="#style/FontLocalizedBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="#string/payment_success"
android:textColor="#color/colorTextPrimary"
android:textSize="24sp"
android:layout_marginStart="24dp"
android:gravity="center"
android:layout_marginEnd="24dp"
android:maxLines="2"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<TextView
android:id="#+id/descriptionTv"
style="#style/FontLocalizedMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="24dp"
android:gravity="center"
tools:text="#string/payment_success_description"
android:textSize="17sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/titleTv" />
<TextView
android:id="#+id/okTv"
style="#style/ButtonTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:paddingBottom="16dp"
android:background="#drawable/save_button_active"
android:text="#string/done"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I have tried with LinearLayout instead of ConstraintLayout, but same result.
I have attached pictures with how my xml file look, and how it looks rendered on emulator, ignore please different string values.
emulator:
xml:
Any idea what can cause the difference in rendering?
Sounds like you need to update the preview style in the xml viewer. I highlighted the drop down box to use in the current release of AndroidStudio.
So around 1% of my daily users are haunted with the NavigationView exception which is caused by an image resource not being found. I find that strange, 99% of other users are just fine. I was hoping that updating my dependancies in version iterations will resolve the issue itself, but unfortunately, this error has stayed in my Crashlytics logs for 6 iterations already and it's the worst crash that is affecting my users.
The obvious thing would be that it is specific to older devices, but this would be a wrong assumption. It is not device specific, neither version specific. Although some specifics can be pointed out
Android Version
90% Andorid 8
10% Android 7
Device
Huawei 50%
Samsung 50%
Two relevant dependancies i'm using:
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
The relevant piece of code in the XML layout:
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:theme="#style/ThemeOverlay.AppCompat.Light"
app:headerLayout="#layout/layout_drawer_header2"
app:menu="#menu/navigation" />
The Header layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/authWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
android:orientation="vertical"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
tools:layout_width="240dp">
<TextView
android:id="#+id/number"
style="#style/Base.TextAppearance.AppCompat.Display3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:fontFamily="sans-serif-medium"
android:textColor="?android:textColorPrimary"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="#+id/car"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/driver"
tools:text="#01" />
<ImageView
android:id="#+id/driverIcon"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
app:layout_constraintBottom_toBottomOf="#+id/driver"
app:layout_constraintStart_toEndOf="#+id/number"
app:layout_constraintTop_toTopOf="#+id/driver"
app:srcCompat="#drawable/ic_person_white_24dp" />
<TextView
android:id="#+id/driver"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"
android:layout_marginTop="16dp"
android:drawablePadding="8dp"
android:ellipsize="end"
android:lines="1"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Body1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/driverIcon"
app:layout_constraintTop_toTopOf="parent"
tools:text="Drivers name" />
<ImageView
android:id="#+id/coDriverIcon"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
app:layout_constraintBottom_toBottomOf="#+id/codriver"
app:layout_constraintStart_toEndOf="#+id/number"
app:layout_constraintTop_toTopOf="#+id/codriver"
app:srcCompat="#drawable/ic_person_white_24dp" />
<TextView
android:id="#+id/codriver"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"
android:drawablePadding="8dp"
android:ellipsize="end"
android:lines="1"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Body1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/coDriverIcon"
app:layout_constraintTop_toBottomOf="#+id/driver"
tools:text="Co-Driver name" />
<ImageView
android:id="#+id/carIcon"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
app:layout_constraintBottom_toBottomOf="#+id/car"
app:layout_constraintStart_toEndOf="#+id/number"
app:layout_constraintTop_toTopOf="#+id/car"
app:srcCompat="#drawable/ic_car_white_24dp" />
<TextView
android:id="#+id/car"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"
android:ellipsize="end"
android:lines="1"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Body1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/carIcon"
app:layout_constraintTop_toBottomOf="#+id/codriver"
tools:text="Racing Car" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<ImageView
android:id="#+id/image"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:srcCompat="#drawable/ic_account_circle_white_24dp" />
<ImageView
android:id="#+id/logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="12dp"
android:tint="#android:color/white"
app:srcCompat="#drawable/ic_log_out" />
</RelativeLayout>
<TextView
android:id="#+id/switchText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="16dp"
android:layout_marginRight="8dp"
android:autoLink="web"
android:gravity="center_vertical"
android:maxLines="2"
android:text="#string/track_me_on_racelivemaps_com"
app:layout_constraintEnd_toStartOf="#+id/trackingOn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/number" />
<Switch
android:layout_width="wrap_content"
android:id="#+id/trackingOn"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content"
android:padding="8dp"
android:autoLink="web"
android:gravity="center_vertical"
android:maxLines="2"
app:layout_constraintBottom_toBottomOf="#+id/switchText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/switchText" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:text="#string/active_stage"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Body2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/switchText" />
<Spinner
android:id="#+id/activeStage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView12" />
</androidx.constraintlayout.widget.ConstraintLayout>
The menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="#string/mode">
<menu>
<group android:checkableBehavior="single">
<item
android:id="#+id/recce"
android:icon="#drawable/ic_write_black_24dp"
android:title="#string/reccemode" />
<item
android:id="#+id/liaison"
android:icon="#drawable/ic_route_black_24dp"
android:title="#string/liaisonmode" />
<item
android:id="#+id/racing"
android:icon="#drawable/ic_racing_flag_black_24dp"
android:title="#string/racemode" />
<item
android:id="#+id/tsd"
android:icon="#drawable/ic_timer_black_24dp"
android:title="#string/tsd" />
<item
android:id="#+id/tsd_advanced"
android:icon="#drawable/ic_tsd_advanced"
android:title="#string/tsd_advanced" />
<item
android:id="#+id/custom_1"
android:icon="#drawable/ic_navigation_layout"
android:title="#string/custom_layout_1" />
<item
android:id="#+id/custom_2"
android:icon="#drawable/ic_navigation_layout"
android:title="#string/custom_layout_2" />
<item
android:id="#+id/custom_3"
android:icon="#drawable/ic_navigation_layout"
android:title="#string/custom_layout_3" />
</group>
</menu>
</item>
<group android:checkableBehavior="none">
<item
android:id="#+id/stages"
android:icon="#drawable/ic_stage_black_24dp"
android:title="#string/special_stages" />
<item
android:id="#+id/settings"
android:icon="#drawable/ic_settings_black_24dp"
android:title="#string/settings" />
<item
android:id="#+id/customize_ui"
android:icon="#drawable/ic_layout_edit"
android:title="#string/customize_ui" />
<item
android:id="#+id/weather"
android:icon="#drawable/ic_weather"
android:title="#string/weather" />
<item
android:id="#+id/login"
android:icon="#drawable/ic_key_white_24dp"
android:title="#string/log_in" />
<item
android:id="#+id/manual"
android:icon="#drawable/ic_manual"
android:title="#string/user_manual" />
<item
android:id="#+id/language"
android:icon="#drawable/ic_translate"
android:title="#string/language" />
<item
android:id="#+id/invite"
android:icon="#drawable/ic_share_black_24dp"
android:title="#string/invite" />
<item
android:id="#+id/feedback"
android:icon="#drawable/ic_feedback_black_24dp"
android:title="#string/feedback_report_bug" />
<item
android:id="#+id/tester"
android:icon="#drawable/ic_tester"
android:title="#string/become_a_tester" />
<item
android:id="#+id/policy"
android:icon="#drawable/ic_policy"
android:title="#string/privacy_policy" />
<item
android:id="#+id/logoff"
android:icon="#drawable/ic_key_white_24dp"
android:title="#string/log_off" />
<item
android:id="#+id/exit"
android:icon="#drawable/ic_exit_to_app_black_24dp"
android:title="#string/exit" />
</group>
</menu>
And finally the crash logs.
android.view.InflateException: Binary XML file line #48: Binary XML
file line #48: Error inflating class
com.google.android.material.navigation.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3173)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3284)
at android.app.ActivityThread.-wrap12(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1894)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7383)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
Caused by android.view.InflateException: Binary XML file line #48:
Binary XML file line #48: Error inflating class
com.google.android.material.navigation.NavigationView
Caused by android.view.InflateException: Binary XML file line #48:
Error inflating class
com.google.android.material.navigation.NavigationView
Caused by java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:658)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at ee.siimplangi.rallytripmeter.activities.MainActivity.onCreate(MainActivity.kt:186)
at android.app.Activity.performCreate(Activity.java:7358)
at android.app.Activity.performCreate(Activity.java:7349)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1219)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3126)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3284)
at android.app.ActivityThread.-wrap12(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1894)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7383)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
Caused by android.view.InflateException: Binary XML file line #29:
Binary XML file line #29: Error inflating class ImageView
Caused by android.view.InflateException: Binary XML file line #29:
Error inflating class ImageView
Caused by android.content.res.Resources$NotFoundException: Resource ID
0x7f0800a5
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:290)
at android.content.res.Resources.getValue(Resources.java:1476)
at androidx.appcompat.widget.AppCompatDrawableManager.createDrawableIfNeeded(AppCompatDrawableManager.java:235)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102)
at androidx.appcompat.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59)
at androidx.appcompat.widget.AppCompatImageView.(AppCompatImageView.java:78)
at androidx.appcompat.widget.AppCompatImageView.(AppCompatImageView.java:68)
at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:783)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.google.android.material.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:207)
at com.google.android.material.navigation.NavigationView.inflateHeaderView(NavigationView.java:281)
at com.google.android.material.navigation.NavigationView.(NavigationView.java:193)
at com.google.android.material.navigation.NavigationView.(NavigationView.java:104)
at java.lang.reflect.Constructor.newInstance0(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:658)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at ee.siimplangi.rallytripmeter.activities.MainActivity.onCreate(MainActivity.kt:186)
at android.app.Activity.performCreate(Activity.java:7358)
at android.app.Activity.performCreate(Activity.java:7349)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1219)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3126)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3284)
at android.app.ActivityThread.-wrap12(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1894)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7383)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
after reading the comments , first of all you have to use android:src because you are not using vector drawable.
This problem occur when we paste image from explorer to drawable folder then it ask whether to copy drawable or drawable-v24 and if you have pasted images in both directory structures, or have one more images with different directory structure then it will show this error, make sure to delete the icon from drawable-v24 after moving it to drawable folder , and clean the project and then run it will work .
I have the following layout for my custom log in dialog
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/padding_large">
<ImageButton android:src="#drawable/ic_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dialog.login.settings"
android:padding="#dimen/margin_medium" />
<TextView android:text="#string/dialog.login.text.user_name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/dialog.login.user_name"
android:layout_width="match_parent"
android:gravity="center"
android:ems="20"
android:layout_height="wrap_content"
android:inputType="text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView android:text="#string/dialog.login.text.password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/dialog.login.password"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox android:id="#+id/dialog.login.show_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/dialog.login.check.show_password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_margin="#dimen/margin_medium"
android:checked="false" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:id="#+id/dialog.login.cancel"
android:drawableStart="#drawable/ic_exit_black"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_medium"
android:text="#string/dialog.login.button.cancel" />
<Button android:id="#+id/dialog.login.connect"
android:text="#string/dialog.login.button.connect"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_marginStart="#dimen/margin_medium"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
when I create the dialog and setcontentview the width of the dialog becomes equal to that of the image button on the first row
if I remove that , it becomes the size of the EditText (dialog.login.user_name) whose ems is 20
when I make the dialog's constructor call the base dialog constructor with a theme of R.style.Theme.Material.Dialog it does get the correct (about 3/4 of the screen) but the problem is that it ignores my primary and accent colours (which is normal)
Is there a way to have the dialog have the Theme.Material.Dialog size but still keep my own primary/accent colours?
thanks in advance for any help you can provide
After a lot of searching it seems that the solution is to actually replace the dialogTheme attribute of my main theme, so the solution was:
<style name="app.theme"
parent="android:Theme.Material.Light.NoActionBar.Fullscreen">
<item name="android:dialogTheme">#style/app.dialog</item>
......
</style>
<style name="app.dialog"
parent="android:Theme.Material.Light.Dialog">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary.dark</item>
<item name="android:colorAccent">#color/accent</item>
</style>