Android 12 SplashActivity theme breaks CardView style - android

There is a custom AlertDialog in my app appearing in SplashActivity as follows:
The XML layout of the AlertDialog is something like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="wrap_content"
app:cardBackgroundColor="#FFFFFF"
app:cardCornerRadius="8dp">
<LinearLayout>
...
</LinearLayout>
</androidx.cardview.widget.CardView>
When I migrate my SplashActivity to new SplashScreen API in Android 12, I have to set its theme as follows:
<activity
android:name=".ui.SplashActivity"
android:screenOrientation="portrait"
android:exported="true"
android:theme="#style/Theme.App.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
As a result, it breaks my custom AlertView as follows:
In conclusion, something breaks app:cardBackgroundColor attribute on CardView which is the root of my custom AlertView
If you look at the broken AlertView carefully, it seems there is a yellow layout over the CardView coming from nowhere.
Any ideas?

Related

The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant)

i am new to Android and i might have a silly / dumb Question. I have got an Activity where i want to dynamically create Multiple Input Fields. The amount of Input Fields is defined by the User.
Because the Input is Styled and Consists of 2 Elements and didnt want to Create these Elements every Time because of Elements have got multiple Parameters that are the same every time. Thats why i created a XML File just for this two Elements which i would like to use in my Programm to Create the Inputs.
View_input.xml
<?xml version="1.0" encoding="utf-8"?>
<merge 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:orientation="vertical"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayoutTableName"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="10dp"
android:hint="#string/create_table_name"
android:inputType="text"
app:boxStrokeColor="#color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:placeholderText="#string/create_table_table_name_placeholder"
app:startIconTintMode="src_in">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textInputName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="" />
</com.google.android.material.textfield.TextInputLayout>
</merge>
My Target XML (activity_create_table_column_names.xml) looks like this:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.createtable.CreateTableColumnNamesActivity">
<LinearLayout
android:id="#+id/columnNameInputContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="start"
android:orientation="vertical"
android:padding="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/create_table_column_names"
android:textStyle="bold" />
<!-- HERE -->
</LinearLayout>
Where i wrote <!-- HERE -->i want all my Input-Fields to be.
I started with just displaying one Input:
private fun initLayout() {
val container = findViewById<LinearLayout>(R.id.columnNameInputContainer)
val inflater = applicationContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(R.layout.view_input, LinearLayout(this))
container.addView(view)
}
But i got the Following Exception:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:115)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:458)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:417)
My Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
...
</style>
</resources>
What am i doing wrong? Is this even the correct way i should programm something like this?
Edit:
Android.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="de.hsos.ma.adhocdb">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:appComponentFactory="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:appComponentFactory">
<activity
android:name=".ui.createtable.CreateTableColumnNamesActivity"
android:parentActivityName=".ui.homescreen.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.createtable.CreateTableActivity"
android:parentActivityName=".ui.homescreen.MainActivity" />
<activity
android:name=".ui.homescreen.TestTableActivity"
android:parentActivityName=".ui.homescreen.MainActivity">
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
<activity
android:name=".ui.TableShow.TableShowActivity"
android:parentActivityName=".ui.homescreen.MainActivity" />
<activity android:name=".ui.tablelist.LayoutTableListItem" />
<activity android:name=".ui.homescreen.MainActivity">
</activity>
</application>
</manifest>
found the solution ,get your inflator from activity not application just modify your initLayout() like this
// here is the fix
val inflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
just set the theme on the chip itself using android:theme="#style/Theme.MaterialComponents.Bridge:
<com.google.android.material.chip.Chip
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:theme="#style/Theme.MaterialComponents.Bridge"****
style="#style/CustomFiltersChipChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:chipStrokeColor="#F0F"
app:chipStrokeWidth="1dp"
app:textEndPadding="10dp"
app:textStartPadding="10dp"
tools:chipText="my chip"
tools:text="Fortune" />
If you don't want your view to change and with on tool bar try this,
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge"/>

How can I view "Hello World!" TextView in Android Studio?

I have just started learning development on Android, and I am not able to view "Hellow World!" TextView in the Design Tab.
MainActivity.java:
package com.dummy.demoapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml:
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dummy.demoapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The TextView appears in the Component Tree, but the preview of the activity is totally blank:
I tried zooming in, but the TextView is just not there.
[EDIT]: The red exclamation (!) gives me the following message:
And refreshing doesn't solve the problem. Any help?
Go to style.xml and change this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
Android Studio sometimes does not appear upto you've success build,
Build->Build&Run, then select your virtual device if there is a helloworld it's okay, it's not your code problem it's related with IDE.
I think it's you default AppTheme with color white , try to add color to TextView
android:textColor="#android:color/black"
Click on the blue icon at the top left corner and then click on force layout. and You will see the Hello World!

EditText is hidden by the softkeyboard in Android

I have a layout in an app with parallax effect on an edittext, my problem is **when I tap on the edittext softkeyboard hides my editext?**Can anybody please help me for this, I have searched for it and found about "WindowsoftInputmode" which is not working in my case.
Code in manifest
<activity
android:name="one.tusk.stush.activities.NewPostDetailActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|adjustPan" >
You should only use android:windowSoftInputMode="adjustResize".
If this is not enough, you might need to add the property android:fitsSystemWindows="true" to the root layout containing your EditText.
Try this in your manifest,
<activity
android:name=".rapcalsy.MainActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Change your layout according this,
dont miss the line which is
android:isScrollContainer="true"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true"
android:orientation="vertical">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#000000"
android:padding="0dp"
android:stretchColumns="*">
...
</TableLayout>
</ScrollView>
Please try this out.
Set an android:softInputMode attribute to adjustResize in Manifest and put the parent layout inside a ScrollView. Hope this helps.
I tried a bit with as you said then i got this working
edit the your manifest file
<activity
android:name="one.tusk.stush.activities.NewPostDetailActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible" >
and then add below line of code in oncreate of java class
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
So that keyboard will not shown to you directly/always

How to enable Split Action Bar?

I want to create an android application which has 3 sliding tab panel and each of them will 5 button (save,new,delete,exit..).
What I want is exactly as follow:
I created sliding tab panel.And for 5 button, I added split action bar.But It works as normal split action bar.My AndroidManifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.belsoft.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:uiOptions="splitActionBarWhenNarrow"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Where is my wrong?
To implement splitActionBar:
Just add android:uiOptions="splitActionBarWhenNarrow" to your activity tag in theAndroidManifest.xml like this...
`<activity
android:name=".MainActivity"
android:uiOptions="splitActionBarWhenNarrow">`<br>
You can read more here and here
NOTE: It is available ONLY for handset devices with a screen width
of 400dp.
To create a custom bottom toolbar:
If you want to set it for all devices, please check my answer (find a post starting with Creating custom bottom toolbar) here:
Creating custom bottom toolbar
I've already created a simple app which should demonstrate you how to
begin
Creating a custom ViewGroup
Here's my activity_main.xml layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
tools:context="com.example.piotr.myapplication.MainActivity">
<LinearLayout
android:id="#+id/show_pdf"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#color/primary_material_light"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_cut_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_copy_mtrl_am_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_selectall_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_paste_mtrl_am_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_share_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_selectall_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_moreoverflow_mtrl_alpha"/>
</LinearLayout>
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"/>
</RelativeLayout>
As you can see my parent ViewGroup is RelativeLayout, which simply
allows me to create a view at the bottom of screen.
Notice that I set layout padding to zero (I think: setting layout
margin to zero here is not necessary, the same effect). If you'd
change it, the toolbar won't use full width and it won't stick with
bottom of the screen.
Then I added a Linear Layout with hardcoded height which is:
android:layout_height="40dp"
I wanted it, that my bottom toolbar would take full available width so
I set it as match_parent.
Next, I added some ImageButton views with images from Android
library.
There you have two possibilities:
if you really want to have a toolbar like in above example just remove in every ImageButton view this line:
android:layout_weight="1"
After removing weights and some buttons you would get a view pretty
similar to expected:
if you want to take the full width and make every button with the same size use in your project weight as in this mine example.
Now let's go to my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.piotr.myapplication"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateVisible|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
In that file I'd added as you can see only one additional line:
android:windowSoftInputMode="stateVisible|adjustResize">
to make sure that device keyboard won't hide my custom bottom toolbar.
From: How to add a bottom menu to Android activity
If you have any question please free to ask.
Hope it help

Error Binary XML file line #2: Error inflating class on android programming

I have an android program with 2 layouts. The first layout is Login. When the login is started first, I have no problem. When I try to change in AndroidManifest from login to splash layout, I got an error. The error is like the title of this posts.
In this android manifest, I change my code from :
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
to :
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Here is the layout for login:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".Login">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:textSize="45dp"
android:gravity="center"
android:id="#+id/tvDisplay"
/>
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Add One"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/bAdd"
android:textSize="20dp"/>
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Substract One"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/bSub"
android:textSize="20dp"/>
And here the layout of splash:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/sertifikat"
tools:context=".Splash"></LinearLayout>
And structure of my code :
Log in logcat:
Here splash.java
How can I fix my code?
Hey You missed some small things
Here is a small example from your code
on Github that i wrote
This is running example of your code
Other than the ending tags
The <intent-filter>
should only be one
most probably the problem lies in your #drawable
as well as look at these tutorials they are great
http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
Obviously,you have lost a character '/' in the splash layout at the end.
You are missing the closing tag of your LinearLayout in splash.xml. Add </LinearLayout> to the end of the file. You also might want to consider using an ImageView with android:scaleType="centerCrop" instead of using a LinearLayout with a background. Using android:background will stretch to fit the size of the screen, which can give a different aspect ratio on different devices, whereas an ImageView will scale it to maintain the aspect ratio (depending on the scaleType).
Also, a LinearLayout is not appropriate for a single image, since it is meant to be a container for other views.
For better performance I recommend you to follow this :
http://www.cutehacks.com/blog/2014/01/13/splash-screens
If you use an high end device you won't see a big difference, but for common devices you will see an huge improvement

Categories

Resources