"You Need to Use a Theme.Appcompat Theme (Or Descendant) with the Design Library" Error

You need to use a Theme.AppCompat theme (or descendant) with this activity

The reason you are having this problem is because the activity you are trying to apply the dialog theme to is extending ActionBarActivity which requires the AppCompat theme to be applied.

Update: Extending AppCompatActivity would also have this problem

In this case, change the Java inheritance from ActionBarActivity to Activity and leave the dialog theme in the manifest as it is, a non Theme.AppCompat value


The general rule is that if you want your code to support older versions of Android, it should have the AppCompat theme and the java code should extend AppCompatActivity. If you have *an activity that doesn't need this support, such as you only care about the latest versions and features of Android, you can apply any theme to it but the java code must extend plain old Activity.


NOTE: When change from AppCompatActivity (or a subclass, ActionBarActivity), to Activity, must also change the various calls with "support" to the corresponding call without "support". So, instead of getSupportFragmentManager, call getFragmentManager.

How to fix: You need to use a Theme.AppCompat theme (or descendant) with this activity

Your application has an AppCompat theme

<application
android:theme="@style/AppTheme">

But, you overwrote the Activity (which extends AppCompatActivity) with a theme that isn't descendant of an AppCompat theme

<activity android:name=".MainActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

You could define your own fullscreen theme like so (notice AppCompat in the parent=)

<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>

Then set that on the Activity.

<activity android:name=".MainActivity"
android:theme="@style/AppFullScreenTheme" >

Note: There might be an AppCompat theme that's already full screen, but don't know immediately

Android You need to use a Theme.AppCompat theme (or descendant) with the design library

try this changes:

in gradle:

compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:design:25.2.0'

Also in manifest add the appcompat theme to your Navaigation drawer `Activity

<activity android:name=".activity.FormActivity"
android:theme="@style/Theme.AppCompat">
<intent-filter>
<action android:name="info.androidhive.navigationdrawer.activity.FormActivity" />

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

How can I fix this error: You need to use a Theme.AppCompat theme (or descendant) with this activity

If you have another styles files in side another values folders like "values-v11", "values-v14"... Edit theme also and try to clean your app before running.

Edited:
From your activity change getApplicationContext() to this:

AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());

to

AlertDialog.Builder builder = new AlertDialog.Builder(this);

Because the dialog also should extends the Appcompat Theme.

You need to use a Theme.AppCompat theme (or descendant) with the design library error

Create a ContextThemeWrapper to wrap the Service's Context with your custom theme, and get the LayoutInflater from that.

ContextThemeWrapper ctx = new ContextThemeWrapper(this, R.style.TranslucentAppTheme);
tooltipContainer = (CoordinatorLayout) LayoutInflater.from(ctx)
.inflate(R.layout.tooltip_layout, null);

ContextThemeWrapper modifies the given Context's theme with the one you specify in the constructor. Since a Service doesn't really have a theme, it just tacks yours onto the Service's Context, then the LayoutInflater has the appropriate theme to inflate the library Views.


Alternatively, if handling it in the layout XML would be more appropriate or less involved, you might be able set an android:theme attribute on the root <ViewGroup>, which simply causes the LayoutInflater to do the Context wrapping internally. For example:

<android.support.design.widget.CoordinatorLayout
...
android:theme="@style/TranslucentAppTheme">

However, this will only work with the platform LayoutInflater starting with Lollipop (API level 21). The support/androidx libraries are able to handle that attribute on older versions, but the way it's set up is intended for use in Activity classes only, and it's likely simpler to just do the wrapping yourself in that case.



Related Topics



Leave a reply



Submit