0

I’m one of Chinese Engineer and My English Speaking is not so good. There is a ListView having some(three or two) GridView Items, and each GridView have some TextView Items.

Now I want to Set the this TextView Item's border-color like the picture refer screenchot then I made some drawable like this code-pic

I set the Item's backgroud property with this drawable. When I was running the app, all of things were working well, but when I click those items found it was not working. There was no border and color change.

How to achive this?

Akshay Katariya
  • 1,464
  • 9
  • 20
chunjie yang
  • 81
  • 1
  • 1
  • 7
  • post your java code – ik024 Jul 17 '17 at 07:54
  • I realized that the first pic may mislead you, you just need see the top 6 items. i want if i click one of this 6, it's color was set as blue , and the others' boder disapeared – chunjie yang Jul 17 '17 at 07:55
  • on clicking textview you have to put yourtextview.setSelected(true); then you will get your result. – Akash Jul 17 '17 at 07:57
  • i tried , maybe it is what i want , i set property textview.setSelected(true), it works. but there is a new problem and i know how to solve it , thanks – chunjie yang Jul 17 '17 at 08:22

2 Answers2

0

try this create drawble file like this

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <stroke android:width="2dp" android:color="@color/colorPrimary" />
        <corners android:radius="10dp" />
    </shape>
</item>

apply to your textview

enter image description here

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0

Make use of android:state_pressed in your dataset_setting_button_selector.xml instead of android:state_activated

https://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html

ik024
  • 3,566
  • 7
  • 38
  • 61