Zahidul
Zahidul

Reputation: 399

Background color in Dialog does not show properly

I used Dialog in my app and sets its layout from xml. When I use the below code it works properly (background color).

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="@dimen/size40"
    android:orientation="vertical"
    android:background="@color/colorPrimary">

</LinearLayout>

But when I use the below code it does not work properly. I tested it in Hwawei TIT-AL00 (Android version 5.1)

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="@dimen/size40"
    android:orientation="vertical"
    android:background="?android:colorPrimary">

</LinearLayout>

Its background color does not show. My project minSdkVersion is 21. I need to use

android:background="?android:colorPrimary

because of my some requirements. Dialog has no custom style and The style I used in activity class is:

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowNoTitle">true</item>
</style>

Upvotes: 1

Views: 84

Answers (1)

Vishu
Vishu

Reputation: 326

Please try 'android:background="?attr/colorPrimary'

Upvotes: 1

Related Questions