Invisible ActionMode item icons in Theme.Sherlock.Light.DarkActionBar

前端 未结 8 2447
一生所求
一生所求 2021-02-13 09:47

When using Theme.Sherlock.Light.DarkActionBar (or Theme.Holo.Light.DarkActionBar, doesn\'t make a difference), the ActionMode (or \"contextual ActionB

相关标签:
8条回答
  • 2021-02-13 10:05

    I had the same problem with application I'm maintaining The solution was very simple - I just had to change compileSdkVersion and targetSdkVersion to latest

    0 讨论(0)
  • 2021-02-13 10:07

    I was fighting with the same issue since last two days. Finally I came up with a workaround!

    I am using a DialogFragment with an AlertDialog object. In the onCreateDialog() method, all we have to do is get the context of the parent activity and set its theme again to Theme.Light.

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        //get the parent activity context and set it's theme again.
        Context ctx = getActivity();
        ctx.setTheme(android.R.style.Theme_Holo_Light);
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.your_dialog_layout, null, false);
        builder.setView(view);
    
        //your other code for the dialog
        //
    
        return builder.create();
    

    Now the icons in the Contextual ActionBar of the EditText have the right color.

    0 讨论(0)
  • 2021-02-13 10:13

    Forcing setTheme on the current context is not a good idea, as it corrupts the theme. To solve that you can use ContextThemeWrapper.

    Context themedContext = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Light);
    final AlertDialog dialog = new AlertDialog.Builder(themedContext)
    
    0 讨论(0)
  • 2021-02-13 10:13

    I tried abovementioned solutions, the only one that worked for me (I have app targeted for API 7, with AppCompat 21.0.3) is to set the dialog style to R.style.Theme_AppCompat. Yes, the stupid dialog is now black. This issue is also present in AppCompat 22.

        final Context themedContext = new ContextThemeWrapper(activity, R.style.Theme_AppCompat);
        builder = new AlertDialog.Builder(themedContext);
        contents = ((LayoutInflater) themedContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.tag_editor, null);
        builder.setView(contents);
    
    0 讨论(0)
  • 2021-02-13 10:16

    Problem:

    App theme is inherited from android:Theme.Light, and there is no dedicated theme for AlertDialog, so that the ActionMode items are somehow invisible.


    Solution:

    1. Create a dedicated theme for AlertDialog;

    <style name="AppTheme" parent="android:Theme.Light">
    </style>
    <style name="AlertDialogTheme" parent="AppTheme">
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowCloseOnTouchOutside">true</item>
        <item name="android:windowActionModeOverlay">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
        <item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
        <item name="android:maxLines">1</item>
        <item name="android:scrollHorizontally">true</item>
        <item name="android:textColor">@android:color/holo_blue_light</item>
    </style>
    

    Note: the most important line which makes the magic is <item name="android:textColor">@android:color/holo_blue_light</item>

    2. Use the dedicated theme when building an AlertDialog.

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme);
    

    Please have a look at the screenshot which shows before and after applying the theme.

    screenshot

    0 讨论(0)
  • 2021-02-13 10:17

    I faced same problem. I use custom theme inherited from Theme.AppCompat.Light. In my theme I overrided actionModeTheme item by my custom style item. But I faced problem as your problem. To solve this problem just override android:alertDialogTheme item in your custom theme.

    <style name="AppTheme" parent="@style/Theme.AppCompat.Light">
            ...
            <item name="android:alertDialogTheme">@style/AppBaseTheme</item>
            ...
    </style>
    
    <style name="AlertDialogTheme">
            ...
            <item name="android:actionModeStyle">@style/ActionModeStyle</item>
            ...
    </style>
    <style name="ActionModeStyle" parent="Widget.AppCompat.Base.ActionMode">
                ...
                <item name="android:background">@color/gray</item>
                ...
    </style>
    

    Note, it works since api 11 level.

    0 讨论(0)
提交回复
热议问题