简体   繁体   English

Android:使用自定义主题为布局设置自定义背景色

[英]Android: Set custom background color for layout using custom theme

i generated custom theme for my app on: http://jgilfelt.github.io/android-actionbarstylegenerator/ 我在以下位置为我的应用生成了自定义主题: http//jgilfelt.github.io/android-actionbarstylegenerator/

And now i would like to add custom color for background of all activities ale fragments in the app. 现在,我想为应用程序中所有活动啤酒片段的背景添加自定义颜色。

I tried to do by this way, but it colors also backgroud of text views and images too (which i don't need). 我试图通过这种方式来做,但是它也为文本视图和图像增添了背景色(我不需要)。

How can i do it to avoid set custom background of the each activity or fragment layout ? 如何避免设置每个活动或片段布局的自定义背景?

Thanks for any advice 感谢您的任何建议

   <style name="Theme.Custom" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarItemBackground">@drawable/selectable_background_custom</item>
        <item name="android:popupMenuStyle">@style/PopupMenu.Custom</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Custom</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Custom</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Custom</item>
        <item name="android:actionBarStyle">@style/ActionBar.Solid.Custom</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_custom</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_custom</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Custom</item>
        <item name="android:background">@color/custom_white</item>

                <!-- Light.DarkActionBar specific -->
        <item name="android:actionBarWidgetTheme">@style/Theme.Custom.Widget</item>

    </style>

You can try adding windowBackground item to your theme, this should color all your activities' backgrounds. 您可以尝试将windowBackground项目添加到主题,这应该为所有活动的背景着色。

<resources>  
  <style name="MyTheme" parent="@android:style/Theme.Light">    
    <item name="android:windowBackground">@color/background</item>  
  </style>
</resources>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在android中自定义主题的布局 - Custom theme of a layout in android 如何使用自定义操作栏背景设置android应用程序自定义主题? - How to set android application custom theme with custom action bar background? 如何定义自定义应用程序主题以在 Android 中为布局指定默认背景? - How to define a custom Application theme to specify a default background for a layout in Android? android设置列表项自定义背景颜色 - android set list item custom background color 如何在自定义键盘 Android 中动态更改键的背景颜色或主题 - How to change background color or theme of keys dynamically in Custom Keyboard Android android:自定义主题无法正确更改文本颜色和背景图像 - android: custom theme does not change text color and background image properly Android:如何在不使用自定义布局的情况下更改 AlertDialog 标题文本颜色和背景颜色? - Android: How can I change AlertDialog Title Text Color and Background Color without using custom layout? 如何在自定义主题的EditText中设置选择颜色? (安卓) - How to set color of selection in EditText in my custom theme? (android) 自定义主题干扰快餐栏背景颜色 - Custom theme interferes with snackbar background color Android 撰写自定义主题 colors - 文本颜色不选择主题颜色 - Android Compose Custom Theme colors - Text color not picking the theme color
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM