나는 간단한 원하는 TextView방식으로 행동 simple_list_item_1A가에 ListView않습니다. XML은 다음과 같습니다.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" android:layout_width="fill_parent"
    android:gravity="center" android:focusable="true"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:background="@android:drawable/list_selector_background" />포커스 상태에서 (예상대로) 변하지 않는 텍스트 색상을 제외한 모든 것이 작동합니다. 로 변경하려면 textAppearanceLargeInverse어떻게합니까?
답변
하나가 작동 할 때까지 여러 테스트를 수행 했으므로 res / color / button_dark_text.xml
<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true"
           android:color="#000000" /> <!-- pressed -->
     <item android:state_focused="true"
           android:color="#000000" /> <!-- focused -->
     <item android:color="#FFFFFF" /> <!-- default -->
 </selector>res / layout / view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
    <Button
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="EXIT"
       android:textColor="@color/button_dark_text" />
</LinearLayout>답변
그리고 셀렉터도 여기에 답입니다.
소스에서 bright_text_dark_focused.xml을 검색하고 res / color 디렉토리 아래 프로젝트에 추가 한 다음 TextView에서
android:textColor="@color/bright_text_dark_focused"답변
다음은 목록의 항목으로 정확히 작동하는 구현입니다 (적어도 2.3 이상).
res / layout / list_video_footer.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <TextView
        android:id="@+id/list_video_footer"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:drawable/list_selector_background"
        android:clickable="true"
        android:gravity="center"
        android:minHeight="98px"
        android:text="@string/more"
        android:textColor="@color/bright_text_dark_focused"
        android:textSize="18dp"
        android:textStyle="bold" />
</FrameLayout>입술 / 색상 /bright_text_dark_focused.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:color="#444"/>
    <item android:state_focused="true" android:color="#444"/>
    <item android:state_pressed="true" android:color="#444"/>
    <item android:color="#ccc"/>
</selector>답변
목록보기에서 선택 작업을 수행하려면 다음 코드를 사용하십시오.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#fff"/>
    <item android:state_activated="true" android:color="#fff"/>
    <item android:color="#000" />
</selector>분명히 열쇠는 state_activated="true"상태입니다.
답변
다음은 선택기의 예입니다. eclipse를 사용하는 경우 ctrl을 클릭하고 공백을 둘 때 : /를 입력해도 무언가를 제안하지 않습니다.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_default_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/btn_default_selected"
    android:state_focused="true"
    android:state_enabled="true"
    android:state_window_focused="true"  />
<item android:drawable="@drawable/btn_default_normal" />참조 할 수 있습니다.
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
답변
나는이 후에 더 이상 검색하지 않고 항상 위의 솔루션을 사용했습니다. 😉
그러나 오늘 나는 무언가를 발견하고 그것을 공유 할 생각을했습니다. 🙂
이 기능은 실제로 API 1에서 사용할 수 있으며 ColorStateList 라고하며 , 여기에서 우리가 이미 알고있는 다양한 상태의 위젯에 색상을 제공 할 수 있습니다.
답변
에서 res/color장소 파일 “text_selector.xml”
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/blue" android:state_focused="true" />
    <item android:color="@color/blue" android:state_selected="true" />
    <item android:color="@color/green" />
</selector>그런 다음 TextView사용하십시오.
<TextView
    android:id="@+id/value_1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Text"
    android:textColor="@color/text_selector"
    android:textSize="15sp"
    />그리고 코드에서는 클릭 리스너를 설정해야합니다.
private var isPressed = false
private fun TextView.setListener() {
    this.setOnClickListener { v ->
        run {
            if (isPressed) {
                v.isSelected = false
                v.clearFocus()
            } else {
                v.isSelected = true
                v.requestFocus()
            }
            isPressed = !isPressed
        }
    }
}
override fun onResume() {
    super.onResume()
    textView.setListener()
}
override fun onPause() {
    textView.setOnClickListener(null)
    super.onPause()
}오류가 발생하여 죄송합니다. 게시하기 전에 코드를 변경했지만 확인하지 않았습니다.
