简体   繁体   English

如何在android中为应用程序的背景着色

[英]How to color the background of the application in android

I added a color folder, with this xml file: 我添加了一个颜色文件夹,这个xml文件:

    <?xml version="1.0" encoding="utf-8"?>
<item
  xmlns:android="http://schemas.android.com/apk/res/android">
    <color name="orange">#FF9912</color>
</item>

But when I put as the value in the screen_display.xml that i created in the values folder. 但是当我将值作为我在values文件夹中创建的screen_display.xml中的值。 It gives me a mistake: 它给了我一个错误:

        <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="MyTheme.Background" parent="@android:style/Theme">
          <item name="android:windowNoTitle"> true</item>
           <item name="android:windowFullscreen">true</item>
           <item name="android:windowBackground">@colors/color/orange</item>
        </style> 
    </resources>

UPDATE
    <activity android:name=".EasyLearningActivity"
                  android:launchMode="singleTask"
                  android:alwaysRetainTaskState="true"
                  android:screenOrientation="portrait"
                  android:configChanges="orientation|keyboardHidden"
                  android:theme="MyTheme.Background"...shows mistake, saying that Strying type inst allowed :(
                  >

pls chk out this in values folder create two xml file first one 请在值文件夹中输出这个,先创建两个xml文件

color.xml color.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

<color name="orange">#FF9912</color>

</resources>

styles.xml styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyTheme.Background" parent="@android:style/Theme">
      <item name="android:windowNoTitle"> true</item>
       <item name="android:windowFullscreen">true</item>
       <item name="android:windowBackground">@color/orange</item>
    </style> 
</resources>

In manifest file: 在清单文件中:

<activity android:name=".EasyLearningActivity"
              android:launchMode="singleTask"
              android:alwaysRetainTaskState="true"
              android:screenOrientation="portrait"
              android:configChanges="orientation|keyboardHidden"
              android:theme="@style/MyTheme.Background"></activity>

You can't use directly string for android:theme . 你不能直接使用字符串android:theme

You need to include one of the styles like **@style/**MyTheme.Background . 您需要包含一个样式,如**@style/**MyTheme.Background

Thanks for the color.xml , finally after 7 hours of research and lots of frustration I now have a purple action bar like I wanted. 感谢color.xml,经过7个小时的研究和很多挫折之后,我现在有了一个像我想要的紫色动作栏。

<color name="orange"     type="color">#FF9912</color>
<color name="red"        type="color">#FF0000</color>

<color name="blue"       type="color">#FF33B5E5</color>
<color name="purple"     type="color">#FFAA66CC</color>
<color name="green"      type="color">#FF99CC00</color>
<color name="darkblue"   type="color">#FF0099CC</color>
<color name="darkpurple" type="color">#FF9933CC</color>
<color name="darkgreen"  type="color">#FF669900</color>
<color name="darkorange" type="color">#FFFF8800</color>
<color name="darkred"    type="color">#FFCC0000</color>
<!--Black   #000000 (0,0,0)
White   #FFFFFF (255,255,255)
Red #FF0000 (255,0,0)
Lime    #00FF00 (0,255,0)
Blue    #0000FF (0,0,255)
Yellow  #FFFF00 (255,255,0)
Cyan / Aqua #00FFFF (0,255,255)
Magenta / Fuchsia   #FF00FF (255,0,255)
Silver  #C0C0C0 (192,192,192)
Gray    #808080 (128,128,128)
Maroon  #800000 (128,0,0)
Olive   #808000 (128,128,0)
Green   #008000 (0,128,0)
Purple  #800080 (128,0,128)
Teal    #008080 (0,128,128)
Navy    #000080 (0,0,12-->

<!--color name="orange" type="color">#FFFFBB33</color-->
<!--<color name="red" type="color">#FFFF4444</color-->

It's @color, not @colors... 这是@color,而不是@colors ......

and are you setting the android:theme attribute for your application tag in the manifest to use MyTheme.Background? 你在清单中为你的应用程序标签设置android:theme属性以使用MyTheme.Background吗?

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

相关问题 如何在android中为Toast自定义背景、背景颜色和文本颜色 - How to customize background, background color and text color for Toast in android 如何在RecyclerView“ Android应用程序”中设置第一行的背景颜色 - How can I set background color of first Row in RecyclerView “Android Application” 在Android应用程序中使用短暂睡眠更新背景颜色 - update background color with short sleeps in between in Android application 如何在Android中更改Spinner选择的背景颜色 - How to Change the background color of Spinner selection in Android 如何更改 android 中的日期选择器背景颜色 - How to change the date picker background color in android 如何将Android背景颜色设置为片段 - How to set android background color into Fragments Android:如何在Java中获取Activity的背景颜色? - Android: How to get background color of Activity in Java? 如何在Android中更改特定日期的背景色? - How to change background color of the particular date in android? Android/Java:如何使用 int Color 设置 MaterialShapeDrawable 的背景颜色? - Android/Java: how to set background color of MaterialShapeDrawable with int Color? Android 将背景颜色与颜色进行比较 - Android Compare Background Color with Color
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM