防止在列表视图中突出显示
我有一个列表视图,我想在其中阻止突出显示选择。列表视图行布局上的背景颜色设置为半透明。我让它越透明,它就越以 Android 默认的橙色突出显示。
这是布局:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/CodeFont"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35sp"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="20dip"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:cacheColorHint="#00000000"
android:background="#AAEBD5A8"
/>
如果我删除背景并像这样设置颜色,
private void makeListDefault(ListView listView) {
int childCount = listView.getChildCount();
int i = 0;
for (i = 0; i < childCount; i++) {
View view = listView.getChildAt(i);
view.setBackgroundResource(R.drawable.hilight_no_gradient_correct_drawable);
}
}
它不会以任何方式影响颜色。 hilight_no_gradient_ Correct_drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FF98FB98" android:endColor="#FF98FB98"
android:angle="90" />
<!-- 98FB98 is a shade of green -->
</shape>
有什么想法吗?我也用选择器尝试过,但似乎没有什么影响颜色。
I have a list view where I'd like to prevent the highlight on selection. The background color is set to be sem-transparent on the list view row layout. The more transparent I make it it, the more it gets highlighted in Android's default orange color.
Here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/CodeFont"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35sp"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="20dip"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:cacheColorHint="#00000000"
android:background="#AAEBD5A8"
/>
If I remove the background and set the color like this,
private void makeListDefault(ListView listView) {
int childCount = listView.getChildCount();
int i = 0;
for (i = 0; i < childCount; i++) {
View view = listView.getChildAt(i);
view.setBackgroundResource(R.drawable.hilight_no_gradient_correct_drawable);
}
}
It's doesn't affect the color in any way. The hilight_no_gradient_correct_drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FF98FB98" android:endColor="#FF98FB98"
android:angle="90" />
<!-- 98FB98 is a shade of green -->
</shape>
Any ideas? I've also tried it with a selector, but nothing seems to affect the color.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 listSelector 定义为透明,如下所示:
它将阻止突出显示/选定状态的默认颜色。
You can define listSelector as Transparent as:
It will prevent the default color for the highlighted/selected state.
您是否尝试过为 ListView 的背景项使用自定义颜色?
请注意listSelector =“....”
backgroundlistcell.xml
也许您需要更改drawable属性值但这应该可行。
Did you try with a custom color for background item of a ListView ?
be aware of listSelector="...."
backgroundlistcell.xml
Maybe you will need to change drawable attribute value but this should work.