Home » Android » android – no resource found that matches the given name Theme.Sherlock.Dialog

android – no resource found that matches the given name Theme.Sherlock.Dialog

Posted by: admin May 14, 2020 Leave a comment

Questions:

Android 2.3.3

I have searched SO for a solution, but I couldn’t understand the solutions given. If someone can explain in a simple way on how to get rid of this error, I would be thankful.

I am using ActionBarSherlock in my application. My basic theme, Theme.Sherlock.Light, works fine with all the activities. For one activity, I want my activity to look like a dialog and hence I wanted to use Theme.Sherlock.Dialog.

Here is my manifest file’s declaration.

<activity
    android:name="com.xxx.xx.x.Activity"
     android:theme="@style/Theme.Sherlock.Dialog" >
</activity>

But I get the following error in my XML : error: Error: No resource found that matches the given name (at 'theme' with value '@style/Theme.Sherlock.Dialog').. Why am I getting this? What should I do, to remove this?

How to&Answers:

Dialog themes in ActionBarSherlock were removed by JakeWharton over four months ago.

https://github.com/JakeWharton/ActionBarSherlock/commit/601bde214b56b8fad0b4fc5aaed5af0b531b6135

Just use @android:style/Theme.Dialog and extend Activity instead of SherlockActivity. ActionBarSherlock doesn’t do anything for dialogs and it will just complain if you’re not using one if its themes.

Answer:

--- res/values-v14/abs__themes.xml
+++ res/values-v14/abs__themes.xml
@@ -26,9 +26,4 @@
       <item name="android:windowActionBar">false</item>
       <item name="android:windowNoTitle">true</item>
     </style>
+
+    <style name="Theme.Sherlock.Dialog" parent="android:Theme.Holo.Dialog">
+    </style>
+    <style name="Theme.Sherlock.Light.Dialog" parent="android:Theme.Holo.Light.Dialog">
+    </style>
 </resources>

Answer:

Theme.Sherlock.Dialog is not supported anymore. I use following approach to style my dialogs in DialogFragment. You can check my dialog templates.

public Dialog onCreateDialog(Bundle savedInstanceState)
{
    ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), getTheme(true));
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    ...
    return builder.create();
}

private int getTheme(boolean light)
{
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    {
        return light ? android.R.style.Theme_DeviceDefault_Light_Dialog : android.R.style.Theme_DeviceDefault_Dialog;
    }
    else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    {
        return light ? android.R.style.Theme_Holo_Light_Dialog : android.R.style.Theme_Holo_Dialog;
    }
    else
    {
        return android.R.style.Theme_Dialog;
    }
}

Answer:

There is no style in ABS as Theme.Sherlock.Dialog.

You may want that activity extend one of the flavors Dialog, e.g.:

    public class MyDialog extends Dialog {
        // Lots of code
    }