android listview快速滚动自定义问题
这是我的列表视图android listview快速滚动自定义问题,android,listview,fastscroll,Android,Listview,Fastscroll,这是我的列表视图 <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/ListView" android:fastScrollEnabled="true" android:divider="@null" style="@drawable/listviewfastscroll
<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>
但是列表视图快速滚动条仍然没有得到定制。您创建的样式不正确。你需要给它起个名字。我不确定你上一篇关于这件事的帖子发生了什么。请执行以下操作:
<?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">
<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>
<com.yourapp.view.FastscrollThemedListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ListView"
android:fastScrollEnabled="true"
android:divider="@null"/>
根据要求,这是我测试的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" />
要更改fastscroll
快速滚动ThumbDrawable
、fastScrollTrackDrawable或fastscroll分段索引器的文本颜色,必须使用上下文主题。其他答案建议通过AndroidManifest
覆盖应用程序的主题。这确实有效,但如果您希望每个ListView
显示不同的滚动条,则不能这样做。此外,在应用程序主题中不应更改SectionIndexer
上的文本颜色,因为这可能会产生其他不需要的效果
为快速滚动设置列表视图
样式的最佳方法是创建一个自定义列表视图
,该视图使用上下文主题包装器
以下是一个例子:
public class FastscrollThemedListView extends ListView {
public FastscrollThemedListView(Context context, AttributeSet attrs) {
super(new ContextThemeWrapper(context, R.style.FastScrollTheme), attrs);
}
}
这就是你所需要的。您的风格将如下所示:
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/CustomTheme">
<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>
<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\u scrollbar\u 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>
AFAIK没有理由设计FastScroll条pre HoneyComb(API 11)不要对您的ListView做任何事情。创建样式,将其应用于清单中的应用程序标记。样式的文件名是否也应为CustomTheme.xml?xml文件的名称是任意的,但它必须使用.xml扩展名并保存在res/values/文件夹中。我已将样式文件直接放在名为listviewfastscrollstyle.xml的values文件夹中。但我得到的编译错误是“D:\30\u JAN\u 2012\res\values\listviewfastscrollstyle.xml:1:error:Invalid start tag Style”。这是>@drawable/listselector@drawable/listselector的代码,请复制并粘贴我的编辑。一切正常。请将答案标记为正确。我当然会接受:)。但它仍然不起作用。.这是样式代码,我已将其直接放在values文件夹@drawable/listselector@drawable/listselector中。非常感谢!您知道我是否可以更改使用此方法滚动时显示的标签的文本大小吗?