2013-05-28 3 views
0

목록보기의 배경을 변경하려면이어떻게 내가 시도 지금까지 목록보기의 배경을 변경하려면

<ListView 
android:id="@+id/myList" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:background="@color/white"/> 

그러나 여기 배경은 뒷면을 보여주는 사실을, 수고 것 같습니다하지 않습니다 기본 달성 방법에 대한 기본 아이디어.

+0

@color/white 란 무엇입니까? "@android : color/white"를 사용해보십시오. –

+0

@ JaredBurrows는 저에게 효과적이지 않았습니다. –

+0

전화를 걸 수있는 곳을 게시 할 수 있습니까? 뭔가 다른 것이 틀림 없거나 ListView의 기본 동작을 변경해야합니까? –

답변

0
<ListView 
android:id="@+id/myList" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:cacheColorHint="#00000000"/> 

사용자 지정 목록보기를 사용하는 경우 listitem latout에서 배경색을 정의하십시오.

listitem.xml //은

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearlayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/artists_list_backgroundcolor" 
    android:baselineAligned="false" 
    android:orientation="vertical" > 
    // Your Listitem widgets 

</LinearLayout> 

이 같은 시도 말 ..

+0

네, 이것이 제가 원했던 것입니다. 당신의 노력에 감사드립니다. –

+0

그러나 목록보기에서 텍스트 색상이나 텍스트를 변경하는 방법 ... –

0

각 listitem 레이아웃의 색상을 변경하십시오. 나는 당신이 생각으로,

public class YourListAdapter extends BaseAdapter { 

    /....Code for Adapter ...../ 

     public View getView(int position, View view, ViewGroup parent) { 
      if (view == null) { 

      view = mInflator.inflate(R.layout.yourxml_listitem, null); 

    /...rest of code for adapter .../ 

가 다음 목록 항목에 대한 XML 레이아웃을 편집하고 각 목록 항목에 배경 색상을 추가 :

당신은 목록 항목에 대한 XML을 찾을 어댑터를 설정하는 경우 다른 색상을 설정하거나 색상을 투명하게 설정하십시오.

+0

그래, 내 경우에 여기에서 알아내는 법을 모르겠다. 런타임에 동적으로 추가 된 listItems가 있으면 조언을 해주십시오. –

+0

런타임에 listitems 배경색을 설정해야합니다. setBackgroundResource (R.color.color_red)를 사용하면 ... –

0

하기로

 <?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="false" android:drawable="@color/BackgroundColor" /> 
    <item android:drawable="@color/white" /> 
</selector> 

그런 다음이 설정 list_bg.xml, 당신이 fisrt.Like 셀렉터를 정의해야합니다 (R.color.color_red)

+0

이 작업을 시도하지 않았습니다. –

0

자원 setBackgroundResource로 설정을 시도하여 배경.

<ListView 
android:id="@+id/myList" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:background="@drawable/list_bg"/> 
+0

이 효과가 없습니다. –

0

이 목록에 대한 사용자 지정 ListAdapter가있는 경우 해당 클래스의 getView() 메서드 내에서 레이아웃을 간단히 변경할 수 있습니다.

당신이 아닌 경우 당신은 사용자 지정 테마 내에서이 두 가지 매개 변수를 변경해야보다

<item name="listChoiceBackgroundIndicator">@android:drawable/list_selector_background</item> 

    <item name="activatedBackgroundIndicator">@android:drawable/activated_background</item> 

내가 다른 요구 사항을 가지고 있기 때문에 나는 사용자 지정 목록 어댑터 내부에 그것을했다 즉, 목록 행 등의 다른 배경 색상과 그것은 잘 작동했다. 두 번째 옵션을 절대로 시도하지는 않았지만 작동해야한다고 믿었습니다 ... 사용자 지정 테마의 다른 대안은 this link을 참조하십시오.

편집 string.xml 내에 스타일 선언과 테마 선언을 쓰지 않습니다.이 파일은 문자열 선언에만 사용됩니다. 참조 값 폴더 안에 파일 themes.xml 만들기 다음 자습서

  1. A simple tutorial
  2. A Good tutorial
  3. The Best tutorial

테마가 만들어지면 .. 당신이 필요로하는 위의 예 중 하나를 참조하십시오 해당 테마를 android-manifiest 파일 안의 Activity/Application에 적용하십시오. 또한 기존 테마를 확장해야합니다.

+0

안드로이드에 대한 새로운 iam은 내 레이아웃에서 참조해야하는 string.xml 안에 작성해야합니다. –

+0

당신이 도움이 될 내 편집을 참조하십시오. – aProgrammer

0

왜 아래 라인을 시도해보세요.

<LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="7dip" 
       android:background="@drawable/list_white_bg" > 

       <ListView 
        android:id="@+id/listView" 
        android:layout_width="wrap_content" 
        android:layout_height="170dip" 
        android:divider="#e0e0e0"      
        android:drawSelectorOnTop="false" 
        android:dividerHeight="1dip" 
        android:fadingEdge="none" > 
       </ListView> 
      </LinearLayout> 
+0

예만 해당 구분선 색상을 배경색으로 변경하지 않습니다. –

0

안드로이드 : = "fill_parent"먼저 확인 UR 배경은 다음과 같이 (확인 UR 목록보기에 모든 다른 사람의 상단에 확인) setBackgroundResource 다른 올바르게 설정되어있는 경우 layout_height

listview.setBackgroundResource (안드로이드. R.color.darker_gray);

u를 통해 UR 자신의 색상

listview.setBackgroundResource(R.color.Yellow);

및 더 많은 색 UR /res/strings.xml 파일

<color name="Yellow">#FF0</color> 의를 원하시면 http://en.wikipedia.org/wiki/Web_colors

0

가있다 안드로이드 2.2에서 그걸로 버그. 가장 좋은 방법은 배경 이미지를 펀트하고 배경을 null로 설정하는 것입니다.

<RelativerLayout 
android:layout_height="wrap_content" 
android:layout_width="wrap_content"> 

    <ImageView 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:src="@drawable/list_bg"/> 

    <ListView 
    android:id="@+id/myList" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:background="@null"/> 

</RelativerLayout> 
+0

예, 좋지만 목록보기에서 텍스트의 색을 변경하는 방법. –

+1

@ user2295109 이것은 다른 질문입니다. [this] (http://windrealm.org/tutorials/android/android-listview.php) 튜토리얼을 통해 도움이 될 것입니다. 그다지 간단하지 않습니다 ... –

+0

네, 덕분에 도움이되었습니다. 많이. –

관련 문제