6

これが私のリストビューです

<ListView android:layout_width="match_parent"
            android:layout_height="match_parent" android:id="@+id/ListView"
            android:fastScrollEnabled="true" android:divider="@null"
            style="@drawable/listviewfastscrollstyle"
            ></ListView>

これはlistviewfastscrollstyleスタイルのファイルです

<style> 
<item name="android:fastScrollTrackDrawable">@drawable/listselector</item> 
<item name="android:fastScrollThumbDrawable">@drawable/listselector</item> 
</style>

これはlistselectorファイルです

<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_pressed="true" android:drawable="@drawable/channelarrows_down" /> 
 <item android:drawable="@drawable/minimize" /> 
 </selector>

しかし、それでもリストビューの高速スクロールバーはカスタマイズされていません。

4

2 に答える 2

9

作成したスタイルが正しくありません。名前を付ける必要があります。これについてのあなたの最後の投稿に何が起こったのかわかりません。以下をせよ:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="listviewfastscrollstyle" parent="android:Theme">
    <item name="android:fastScrollTrackDrawable">@drawable/listselector</item>
    <item name="android:fastScrollThumbDrawable">@drawable/listselector</item>
</style>

</resources>

マニフェストで、次のようなスタイルを設定します。

<application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:theme="@style/CustomTheme">

要求に応じて、これは私がテストしていたListViewです。

<ExpandableListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:drawSelectorOnTop="false"
    android:fastScrollAlwaysVisible="true"
    android:fastScrollEnabled="true"
    android:indicatorLeft="8dip"
    android:indicatorRight="52dip"
    android:paddingRight="32dip" />
于 2012-02-08T06:02:09.460 に答える
8

fastScrollThumbDrawablefastScrollTrackDrawable、または fastscroll のテキストの色を変更するにSectionIndexerは、コンテキスト テーマを使用する必要があります。他の回答では、これを行うためにアプリケーションのテーマをオーバーライドすることを推奨しAndroidManifestています。それは機能しますが、スクロールバーごとに異なる外観が必要な場合は、それListViewを行うことはできません。また、テキストの色を変更する方法SectionIndexerは、アプリのテーマで行うべきではありません。他の望ましくない効果が生じる可能性があるためです。

高速スクロール用に をスタイルする最良の方法は、 を使用ListViewするカスタムを作成することです。 ListViewContextThemeWrapper

次に例を示します。

public class FastscrollThemedListView extends ListView {
    public FastscrollThemedListView(Context context, AttributeSet attrs) {
        super(new ContextThemeWrapper(context, R.style.FastScrollTheme), attrs);
    }
}

必要なのはそれだけです。スタイルは次のようになります。

<style name="FastScrollTheme">
    <item name="android:textColorPrimary">?android:textColorPrimaryInverse</item>
    <item name="android:fastScrollThumbDrawable">@drawable/fast_scrollbar_thumb</item>
    <item name="android:fastScrollTrackDrawable">@drawable/fast_scrollbar_track</item>
</style>

textColorPrimarySectionIndexerフックする方法は、フォントの色を使用する場合にフックする方法です。

ListView は次のようになります。

<com.yourapp.view.FastscrollThemedListView 
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:id="@+id/ListView"
    android:fastScrollEnabled="true" 
    android:divider="@null"/>

必要に応じて、ThumbDrawable は次のようになります。

fast_scrollbar_thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="10dp" android:bottom="10dp">
        <shape android:shape="rectangle">
            <size
                android:height="45dp"
                android:width="5dp" />
            <solid android:color="#DA414A" />
        </shape>
    </item>
</layer-list>

私の知る限り、FastScroll バーを HoneyComb の前にスタイルする理由はありません (API 11)

于 2014-03-05T22:32:31.520 に答える