Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I Use @styles/Theme.MyComposeTheme on AndroidManifests.xml? #265

Closed
ydhnwb opened this issue Jan 8, 2023 · 3 comments
Closed

Can I Use @styles/Theme.MyComposeTheme on AndroidManifests.xml? #265

ydhnwb opened this issue Jan 8, 2023 · 3 comments

Comments

@ydhnwb
Copy link

ydhnwb commented Jan 8, 2023

I'm learning to implement SimpleStack into Compose (material3) project. Navigation seems to be works perfectly and easy to understand, but the only problem is, when I use default theme that comes when creates Compose (material3) project, it force-close and shows me error like this:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ydhnwb.learnjetpacknav/com.ydhnwb.learnjetpacknav.app.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                                                    	

Here is my manifest.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">

    <application
        android:name=".app.CustomApplication"
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.LearnJetpackNav"
        tools:targetApi="31">
        <activity
            android:name=".app.MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.LearnJetpackNav">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
    </application>

</manifest>

So, I tried to create a new theme on themes.xml like below just to make it work

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">#000</item>
        <item name="colorPrimaryDark">#000</item>
        <item name="colorAccent">#000</item>
    </style>

<!--    can i use below style? -->
    <style name="Theme.LearnJetpackNav" parent="android:Theme.Material.Light.NoActionBar" />
</resources>

then on manifest, I replaced the @styles/Theme.LearnJetpackNavTheme into @styles/AppTheme

It works, but is it okay?
Is it affecting app theme like dynamic color (for android12+) or not? I just worried about that. I also wrap my app view like this:

image

Here is my repo (just in case)
*all my code is based on this extension-compose-example

@Zhuinden
Copy link
Owner

Zhuinden commented Jan 9, 2023

Simple-Stack out of the box has no dependency on AndroidX nor AppCompat at all, but Fragments and Material Components that you use, might. In that case, the theme you define should inherit from a parent theme that is requested by your views (both AppCompat alone, and Material-Components has its own themes that they expect to be used as a parent).

@ydhnwb
Copy link
Author

ydhnwb commented Jan 9, 2023

Yes. Since I use extends MainActivity with AppCompatActivity to get the "supportFragmentManager", I need to use AppCompat theme.

The default when creating Material3 Compose is extending MainActivity with ComponentActivity, but using it make me unable to get supportFragmentManager

image

image

Update: I found the solution

@ydhnwb ydhnwb closed this as completed Jan 9, 2023
@Zhuinden
Copy link
Owner

Zhuinden commented Jan 9, 2023

To use fragments, you might need either FragmentActivity or AppCompatActivity

FragmentActivity should also be a subclass of ComponentActivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants