开发者

change background of textview for listview item get focused

开发者 https://www.devze.com 2023-04-07 06:25 出处:网络
i have this listview each listview item has a 开发者_StackOverflowtextview that have background , i want to change the background of the textview of listview itemget focused .You should use Selector

i have this listview

change background of textview for listview item get focused

each listview item has a 开发者_StackOverflowtextview that have background , i want to change the background of the textview of listview item get focused .


You should use Selector.
Edit: Use selector drawable as a background for ListView elements, or specify a android:listSelector for a ListView


you have change background color in onfocusChangeListener. Try with following code,

livView.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {

                TextView tv=(TextView)v.findViewById(R.id.yourId);
                if(hasFocus){
                    tv.setBackgroundColor(bg_color);
                }
            }
        });
0

精彩评论

暂无评论...
验证码 换一张
取 消