简体   繁体   中英

Removing focus indicator from RecycleView in Android

I have an app using RecyclerView , and on the tablet I get a light blue background showing. Particularly on Jelly Bean devices and in the emulator. I've tried to remove it by marking my RecyclerView as android:focusable="false" I know it's the focus indicator since on the emulator if I hit the tab key it goes away and highlights a button on the UI. It doesn't show up on the phones I've used.

So why is it being rendered on a touch device? And how do I get rid of it?

That's the style of your recyclerView item. Use selectors

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_pressed="true" android:drawable="@color/pressedStateColor" />
   <item android:state_focused="true" android:drawable="@color/focusedStateColor" />
   <item android:drawable="@color/normalStateColor" />
</selector>

If you don't what any color to show just give the same color to the focused state or try "@android:color/transparent" .

Then set your android:background="@drawable/your_above_xml"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM