Android SetBackgroundResource& SetBackground不工作前棒棒糖

时间:2015-09-26 09:37:02

标签: android xml layout android-studio setbackground

我正在使用基于Lollipop的avd开发我的应用程序,其中我使用SetBackgroundResource使用自定义drawable(layer-list)设置listview行的背景。它完美无缺。

LinearLayout xml行的默认定义背景为蓝色。

Jelly Bean和Kit Kat,使用SetBackgroundResource删除默认的蓝色,但它没有将其设置为所请求的背景drawable。在将minsdk从15改为16之后,我也尝试了SetBackground。

仍然没有快乐。

((LinearLayout)v.getParent()).setBackgroundResource(R.drawable.border_purple);

我也试过了;

((LinearLayout)v.getParent()).setBackground(ContextCompat.getDrawable(context,R.drawable.border_orange));

行xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent" android:layout_width="match_parent"
android:orientation="vertical"
android:background="@drawable/border_blue"
android:padding="12dp"
android:layout_marginBottom="16dp"
android:id="@+id/layout_row">
<TextView
    android:layout_height="wrap_content"
    android:id="@+id/item_title"
    android:text=""
    android:layout_width="match_parent"
    android:textSize="20sp"
    android:textColor="@color/primary_dark_material_light"
    android:background="#FFFFFF"/>
<View
    android:layout_width="match_parent"
    android:layout_height="2px"
    android:background="#D3DFE3" />
<TextView
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:id="@+id/item_byline"
    android:text=""
    android:background="#FFFFFF"/>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

经过进一步调查后,它正在运行,但它从LinearLayout中删除了填充,因此它似乎没有工作。我相信它也从Layer-list中删除了填充。