开发者

set background colors for text and listview, listview does not change the color with setbackground

I have a view with listview and text view. I want to set diff colors for textview and listview. also list view also few items which does not fill entire screen.

need help to fix the issue

<TextView android:id="@+id/textView1" android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_weight="0.12" android:layout_width="match_parent"
    android:text="@string/songsbyyear" android:gravity="center"
    android:textColor="@color/white" android:textSize="22dp"
    android:background="@color/steelblue" android:textStyle="bold"></TextView>
<ListView android:layout_width="wrap_content"
    android:drawSelectorOnTop="false" android:id="@android:id/list"
    android:background="@color/darkslateblue"  android:layout_height="456dp">    </ListView>

First screen xml

<TextView android:id="@+id/textView1" android:layout_h开发者_如何学JAVAeight="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_weight="0.12" android:layout_width="match_parent"
    android:text="@string/songsbyyear" android:gravity="center"
    android:textColor="@color/white" android:textSize="22dp"
    android:background="@color/steelblue" android:textStyle="bold"></TextView>
<ListView android:layout_width="wrap_content"
    android:id="@android:id/list"
    android:drawSelectorOnTop="true" android:divider="#FFCC00"    android:dividerHeight="4px"
    android:background="@color/darkslateblue" android:layout_height="456dp">  </ListView>


You need to provide drawable or Hex code for color to be the background. As you are getting this

Unable to resolve drawable "@color/steelblue" in attribute "background"
Unable to resolve drawable "@color/darkslateblue" in attribute "background"

So, provide an image and you can also use values like this "#FF00FF" etc

EDIT:

I have included a file my_color.xml in my values folder i.e. res/values/my_color.xml.

And my_color.xml inludes:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="white">#ffffff</color>
  <color name="steelblue">#4863A0</color>
  <color name="darkslateblue">#2B3856</color>
</resources>

It's working for me. Try this now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜