2014-02-13 5 views
0

내 질문의 제목은 내가 묻고 싶은 것을 요약합니다. 설명에서 내 질문을 자세히 설명합니다.Android에서 ExpandableListView의 배경색을 변경하는 방법은 무엇입니까?

그래서 나는 ExpandableListView를 가지고 있으며 내부에 흰색 텍스트가있는 검정색으로 화면에 인쇄됩니다. 목록을 누르면 해당 항목이 소비되고 세부 정보를 선택할 수 있습니다. 그것은 다음과 같은 :

|--------------------------| 
|black color    | 
| Title text(in white) | 
|       | 
|__________________________| 
| Item 1 (black text with white background) 
| Item 2     | 
| Item N...    | 

그래서 제 질문은 "텍스트 제목"내부의 배경색을 변경하고 제목에 표시되는 문자의 수에 대한 제한을 넣어하는 방법은?

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="228dp" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#f4f4f4" 
     android:orientation="vertical" > 

     <ExpandableListView 
      android:id="@+id/lvExp" 
      android:layout_width="match_parent" 
      android:layout_height="485dp"   > 
     </ExpandableListView> 
    </LinearLayout> 
    </ScrollView> 

항목 : 여기

내 XML 파일입니다. XML :

<?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="55dip" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/lblListItem" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textSize="17dip" 
    android:paddingTop="5dp" 
    android:paddingBottom="5dp"   
    android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" /> 


</LinearLayout>  

Group.XML

<?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" 
android:padding="8dp" 
android:background="#000000"> 


<TextView 
    android:id="@+id/lblListHeader" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft" 
    android:textSize="17dp"   
    android:textColor="#f4f4f4" 
    android:background="#323232"/>//this only changes some part of the background just around the text ONLY 

</LinearLayout> 
+0

당신이 무엇을 의미합니까 "을 제목에 표시되는 문자의 수에 대한 제한을 넣어"? – Shahzeb

+0

예를 들어 제목이 "고기 먹기를 좋아합니다"라는 메시지가 나타나면 "나는 먹기를 좋아합니다 ..." – user3182266

+0

android : singleLine = "true"속성의 텍스트 뷰 – Shahzeb

답변

1

는 텍스트 뷰에서 이러한 속성을 시도해보십시오 expandablelistadapter에서

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:maxLines="1" 
    android:maxLength="10" 
    android:ellipsize="marquee"/> 
+0

좋은 고마워요. 마지막 질문 하나가 문자 수가 줄어든 후에 "..."을 추가 할 수 있습니까? – user3182266

+1

글자 수를 제한하고 글자 수가 제한을 초과하지 않으면 전체 텍스트를 인쇄합니다. 자바에서 onTextChanged 이벤트를 재정의하고 텍스트 끝에 "..."을 추가하여이 작업을 수행 할 수 있습니다. – Shahzeb

+0

다시 한 번 감사드립니다! – user3182266

0

: getGroupView에서를

if (convertView == null) { 
      LayoutInflater infalInflater = (LayoutInflater) this.mContext 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.listheader, null); 
     } 

아래 : 생을 넣어 S :

convertView.setBackgroundColor(Color.parseColor("#FFFFFF")); 

그리고 제목 문자는 XML에서 사용하는 텍스트 제한 :

<TextView 
android:id="@+id/secondLineTextView" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:maxLines="1" 
android:maxLength="10" 
android:ellipsize="end"/> 
관련 문제