Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 动态更改背景颜色并使用边框_Android - Fatal编程技术网

Android 动态更改背景颜色并使用边框

Android 动态更改背景颜色并使用边框,android,Android,我有以下模板 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" an

我有以下模板

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@drawable/borders" >

    <RelativeLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp">

        <ImageView
            android:id="@+id/category_starred_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/rating_not_important"
            android:contentDescription="@string/app_name" />

        <TextView
            android:id="@+id/category_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/category_starred_icon"
            android:textIsSelectable="false"
            android:textSize="18sp"
            android:paddingLeft="5dp"
            android:paddingTop="5dp"
            android:paddingRight="5dp"
            android:textColor="@android:color/white"
            android:hint="@string/category"  />
    </RelativeLayout>

</LinearLayout>
我丢失了边框,如何在不丢失边框的情况下解决警告,主要问题是背景颜色是动态的

看看这个:

这是一个可绘制文件,用于在图层列表中组织其他可绘制文件(一个在另一个之上)。有了它,您可以使用其他绘图工具(如形状)以您想要的方式定义边框和背景


我现在不能给出一个完整的答案,但是如果你搜索这个,我相信你能做到。当我有更多时间时,如果你还没有找到解决方法,我可能会回来帮助你。

你可以删除线性布局,只使用相对布局,然后将
android:background=“@drawable/borders”
设置为相对布局是的,但我需要同时显示
android:background=“@drawable/borders”
和由code设置的背景色我认为同一布局不可能
mLayout
是LinearLayout还是RelativeLayout对象?该警告为线头警告,是,该警告为线头警告
mLayout.setBackgroundColor(Color.paseColor(mColorString));