How do I create a button like AppCompat AlertDialog button?
I want to overlay a system window.
I am trying to create a button like AppCompat style.
I've 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 works in AppCompat but not AppCompat.Light. I have a button from AppCompat style (dark). Screenshots:
Dark (working):
Dark focusing (working):
Light (works):
Focused light (not working):
In this image, we can see that everything is in order. However, it looks ugly on the phone.
I want to make this button (I created in this same application this same AlertDialog theme using android.support.v7.app.AlertDialog) and it looks ok:
I don't know why it doesn't work. How should I do it? The problem is related to the background of the button when focusing. I don't know why the background is in dark style. I tried to install theme AlertDialog.AppCompat.Light but doesn't work.
source to share