0

I add overlay layout via WindowManager to the screen and I have button there with android:theme parameter:

FrameLayout view = (FrameLayout) View.inflate(this, R.layout.button_view, null);

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.MATCH_PARENT,
        WindowManager.LayoutParams.MATCH_PARENT,
        WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
        PixelFormat.TRANSLUCENT
);
windowManager.addView(view, params)

button_view

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme">

    <Button
        style="@style/Widget.AppCompat.Button.Borderless.Colored"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/button_text"
        android:theme="@style/AppTheme"
        tools:ignore="UnusedAttribute" />
</FrameLayout>

And AppTheme:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/color_primary</item>
    <item name="colorPrimaryDark">@color/color_primary_dark</item>
    <item name="colorAccent">@color/color_accent</item>
    <item name="android:windowBackground">@color/white</item>
</style>

The color color_accent is blue and on emulators with api 23-25 the color of button is also blue.

But on emulator with api 16 it's light gray and on on emulator with api 22 it is red.

How can I fix that?

When I add this button with this theme to the activity's layout, it works.

shmakova
  • 6,076
  • 3
  • 28
  • 44

0 Answers0