I want to overlay system window.
I'm trying to create button like AppCompat style.
I have tried this:
XML:
<LinearLayout
...
android:background="?android:attr/windowBackground"
/>
<!--
My layout ...
And button
The buttonBarButtonStyle is in Theme.AppCompat and Theme.AppCompat.Light
-->
<Button
style="?attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close" />
Service:
LayoutInflater inflater;
public void setTheme(int theme)
{
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this, theme);
inflater = LayoutInflater.from(this).cloneInContext(contextThemeWrapper);
}
public void onCreate(){
boolean themeDark = getThemeDark();
setTheme(themeDark ? R.style.Theme_AppCompat : R.style.Theme_AppCompat_Light);
super.onCreate();
createView(); // in this method i'm only inflating view using: inflater.inflate(layoutId, null); and adding view to window
}
And it's working in AppCompat but not in AppCompat.Light. I have the button from style AppCompat (dark). Screenshots:
Dark (works):

Dark focused (works):

Light (works):

Light focused (not working):

In this image we can see all is ok. However in a phone it looks ugly.
I want to make this button (I have created in this same app with this same theme AlertDialog using android.support.v7.app.AlertDialog) and it's looks ok:

I don't know why it's not working. How can I do it? The problem is with button background when focused. I don't know why the background is from dark style. I was tried to set AlertDialog.AppCompat.Light theme but not working.
I have fixed it.
I replaced Button with android.support.v7.widget.AppCompatButton.
<android.support.v7.widget.AppCompatButton
style="?attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close" />
Now it's working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With