3
android Pallete
을 사용하여 코드에서 선형 레이아웃에 맞춤 색상을 설정하려고합니다.LinearLayout.setBackgroundColor (int)가 Android에서 작동하지 않습니다.
코드는 아래와 같습니다 :
public void changeColour(Pallete palette){
v = li.inflate(R.layout.contact_info, null);
contactInfo = (LinearLayout)v.findViewById(R.id.contact_layout);
contactInfo.setBackgroundColor(palette.getDarkMutedSwatch().getBodyTextColor());
}
나는 또한이 같은 배경을 설정할 수를 사용하여 다음 ColorDrawable
는 제하기 위해 노력했다.
ColorDrawable cd = new ColorDrawable(palette.getDarkMutedSwatch().getBodyTextColor());
contactInfo.setBackground(cd);
하지만 이렇게해도 작동하지 않습니다. contactInfo
은 ListView
의 요소입니다. 목록 항목
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="5dp"
android:id="@+id/contact_layout"
android:weightSum="3">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/pic"
android:src="@drawable/image" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="2.6"
android:layout_margin="5dp"
android:paddingLeft="10dp"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/name"
android:text="User name"
android:textSize="24dp"
android:textColor="#ffffff"/>
</LinearLayout>
<LinearLayout
android:layout_weight="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:gravity="center"
android:visibility="gone"
android:orientation="horizontal">
<CheckBox
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/check" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Pallete 란 무엇입니까? android.support.v7.graphics.Palette를 의미합니까? –
예 android.support.v7.graphics.Palette; –
setBackground 대신 setBackgroundColor를 사용해 보셨습니까? –