Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppCompat Dialog Theme with Mis-colored titlebar - Bug?

I have a LoginActivity where I use an AppCompat theme like this:

 <activity
            android:name=".LoginActivity"
            android:theme="@style/Theme.AppCompat.Light.Dialog"
            android:label="Login" />

I am aware that as of this post Google has not yet added Material Themes in AppCompat library for DIALOGS, so I assumed it will fall back on Holo. Instead, this is what I get:

enter image description here

Keep in mind, I am not using the AppCompat toolBar. In the Activity, I am not even making a reference to the ActionBar. What you see above is default behavior, yet I cannot figure out where it is coming from. Is this a bug perhaps?

(Also, the EditText fields are not being colored with the Primary color for the app.)

like image 784
TheLettuceMaster Avatar asked Oct 27 '14 19:10

TheLettuceMaster


1 Answers

Note: see my final edit for possibly the best solution

For what it's worth, I do think this is a bug. However, a valid workaround that I discovered is to use @style/Base.Theme.AppCompat.Light.Dialog.FixedSize. Based on your screenshot I think this will work for you as well. However, I have not tested palette coloring yet.

From what I can tell in my testing, this extends the gray border while still allowing you to use AppCompat and v21.

Edit: one side-effect is it now appears that all dialog activities are the same size, which may not work for you. Also, I haven't figured out how to remove the title - requestWindowFeature and supportRequestWindowFeature with Window.FEATURE_NO_TITLE seems to be causing

java.lang.RuntimeException: Unable to start activity ComponentInfo{myclass}:
android.util.AndroidRuntimeException: requestFeature() must be called before adding content

even though I've tried it before and after super.onCreate and definitely before setContentView

Edit#2: Removing the title via XML theming works, and since you have no title there is no bizarre gray box to worry about, which means you can drop the FixedSize setting and the dialog will wrap it's content like it did in earlier versions.

<style name="MyActivityDialogTheme" parent="Base.Theme.AppCompat.Light.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

Edit #3: You can also just simply remove the gray background - this may be the best solution because it does not require the Base. prefix:

<style name="MyTitledActivityDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowTitleBackgroundStyle">@android:color/transparent</item>
    <item name="windowActionBar">false</item>
</style>
like image 85
Mick Avatar answered Oct 24 '22 08:10

Mick