2016-09-13 1 views
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); 

하지만 이렇게해도 작동하지 않습니다. contactInfoListView의 요소입니다. 목록 항목

<?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> 
+1

Pallete 란 무엇입니까? android.support.v7.graphics.Palette를 의미합니까? –

+0

예 android.support.v7.graphics.Palette; –

+0

setBackground 대신 setBackgroundColor를 사용해 보셨습니까? –

답변

0

에 대한

XML이 나는 문제를 발견했다. 배열 어댑터의 레이아웃 색상이 바뀌 었습니다. 해결책은 아래와 같습니다.

public View getView(int i, View convertView, ViewGroup viewGroup) { 
     View view = convertView; 
     view.findViewById(R.id.contact_layout).setBackgroundColor(Color.BLUE) 

그래서 개체 배열을 통해 배열 어댑터에 색상을 전달하면 내 문제를 해결할 수있었습니다.

관련 문제