问题
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:
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.)
回答1:
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>
来源:https://stackoverflow.com/questions/26595128/appcompat-dialog-theme-with-mis-colored-titlebar-bug