【问题标题】:Android - Cannot set the LIstView background color use ListFragementAndroid - 无法使用 ListFragement 设置 LIstView 背景颜色
【发布时间】:2021-09-27 14:17:58
【问题描述】:

我创建了一个colors.xml并有一个list_fragment.xml如下,listView的背景颜色没有变成蓝色?

colors.xml

           <?xml version="1.0" encoding="utf-8"?>
               <resources>
                  <color name="colorPrimary">#008577</color>
                  <color name="colorPrimaryDark">#00574B</color>
                  <color name="colorAccent">#D81B60</color>
                  <color name="orange">#ff5500</color>
                  <color name="transparent">#00000000</color>
                  <color name="black">#000000</color>
                  <color name="gray">#999999</color>
                  <color name="blue">#0066cc</color>
            </resources>

list_fragment.xml

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:tools="http://schemas.android.com/tools"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         tools:context=".HomePageListFragment">


       <ListView
         android:id="@android:id/list"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:background="@color/blue"
       </ListView>

     </LinearLayout>enter code here

谢谢, 乔

【问题讨论】:

  • 您是否在列表中填充了非蓝色的项目?
  • 嗨,布鲁斯,你用项目填充列表是什么意思?这个属性怎么设置?

标签: android listview


【解决方案1】:

您的 XML 格式不正确:

  <ListView
     android:id="@android:id/list" <=== change it to android:id="@+id/list"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@color/blue"  <=== missing ">" to close the tag
   </ListView>

【讨论】:

  • 感谢您的回复!我试图关闭它仍然无法正常工作的标签。
  • 这很奇怪这工作得很好:schemas.android.com/apk/res/android" xmlns:tools="@987654322 @" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
  • 我把id标签也改成了android:id="@+id/list",颜色还是没变。我正在使用 Android Studio 4.0
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-06
  • 2013-08-04
  • 1970-01-01
  • 2012-06-04
  • 2014-03-29
  • 1970-01-01
  • 2023-03-06
相关资源
最近更新 更多