I am using drawable as image background for giving border but its not working as required (circle is not perfect).
Recycler view item layout
<data>
<variable
name="news"
type="com.android.mvvm.model.NewsItem" />
<variable
name="clickListener"
type="com.android.common.util.RecyclerViewOnItemClickHandler"></variable>
</data>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circular_image_selected"
android:layout_width="100dp"
android:layout_height="100dp"
android:onClick="#{clickListener.onClick}"
android:src="#{news.thumb}" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/circular_image_unselected"
android:layout_width="100dp"
android:layout_height="100dp"
android:onClick="#{clickListener.onClick}"
android:src="#{news.thumb}"
android:visibility="gone" />
</FrameLayout>
Adapter's onBindViewHolder method where i am setting background to the image view on item selected
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof RecyclerViewHolder) {
NewsItem item = list.get(position);
RecyclerViewHolder newsViewHolder = (RecyclerViewHolder) holder;
if (item.isSelected) {
CircleImageView img = (CircleImageView) newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_unselected);
newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_unselected).setVisibility(View.VISIBLE);
img.setBackground(context.getResources().getDrawable(R.drawable.selected_img_bg));
} else {
CircleImageView img = (CircleImageView) newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_selected);
img.setColorFilter(Color.argb(150, 155, 155, 155), PorterDuff.Mode.SRC_ATOP);
newsViewHolder.getBinding().getRoot().findViewById(R.id.circular_image_unselected).setVisibility(View.INVISIBLE);
}
newsViewHolder.getBinding().setVariable(BR.clickListener,
new RecyclerViewOnItemClickHandler<>(item, position, listener));
newsViewHolder.getBinding().setVariable(BR.news, item);
newsViewHolder.getBinding().executePendingBindings();
}
}
Drawable for image background
<?xml version="1.0" encoding="utf-8"?><shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#android:color/transparent" />
<stroke android:color="#android:color/holo_red_dark" android:width="3dp"/>
<size
android:width="100dp"
android:height="100dp"/>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:useLevel="false"
android:thickness="7.8dp"
android:innerRadius="0dp"
>
<solid
android:color="#F00"
/>
<stroke
android:width="1dip"
android:color="#FFF" />
use this as background to you image... increase thickness accordingly.. or if this doesn't work retain the previous background xml and add android:padding around 10 to 15 dp in your imageview
i solve this by placing imageview into relativelayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_margin="5dp"
android:padding="2dp"
android:background="#drawable/imageborder"
android:src="#drawable/placeholder"
android:id="#+id/notificator_image"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<stroke android:width="2dp"
android:color="#cc195d" />
</shape>
Related
I am trying to make a custom background for my button(simple) but it is not displaying properly. it only displays the following output.
Create Room(btn_create_room_bg) :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<corners
android:bottomLeftRadius="360dp"
android:topLeftRadius="360dp" />
<solid android:color="#color/colorAccent" />
</shape>
</item>
</layer-list>
Join Room(btn_join_room_bg):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners
android:bottomRightRadius="360dp"
android:topRightRadius="360dp" />
<solid android:color="#color/colorPrimary" />
</shape>
</item>
</layer-list>
Button code:
Here are my two-button codes in a linear layout.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="300dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="300dp"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginEnd="8dp"
android:layout_weight="5"
android:background="#drawable/btn_create_room_bg"
android:fontFamily="#font/open_sans_bold"
android:text="#string/landing_btn_create_room"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
<Button
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginStart="8dp"
android:layout_weight="5"
android:background="#drawable/btn_join_room_bg"
android:fontFamily="#font/open_sans_bold"
android:text="#string/landing_btn_join_room"
android:textAllCaps="false"
android:textColor="#color/colorWhite" />
</LinearLayout>
I need an output like this.
You can build a custom CornerTreatment with the MaterialButton.
You can extend the default CutCornerTreatment:
public class FullCutCornerTreatment extends CutCornerTreatment {
protected static final float ANGLE_LEFT = 180;
public FullCutCornerTreatment() {
super();
}
#Override
public void getCornerPath(
#NonNull ShapePath shapePath, float angle, float interpolation, float radius) {
shapePath.reset(0, 2*radius * interpolation, ANGLE_LEFT, 180 - angle);
shapePath.lineTo(
(float) (Math.sin(Math.toRadians(angle)) * radius * interpolation),
(float) (Math.sin(Math.toRadians(90 - angle)) * radius * interpolation));
}
}
Then just apply the CornerTreatment to the Button:
MaterialButton materialButton = findViewById(R.id....);
FullCutCornerTreatment customCutCornerTreatment = new FullCutCornerTreatment();
materialButton.setShapeAppearanceModel(materialButton.getShapeAppearanceModel().toBuilder()
//Standard rounded corner with corner radius=50%
.setTopLeftCorner(CornerFamily.ROUNDED,new RelativeCornerSize(0.5f))
.setBottomLeftCorner(CornerFamily.ROUNDED,new RelativeCornerSize(0.5f))
//Square angle
.setTopRightCorner(CornerFamily.ROUNDED,0)
//Full cut corner
.setBottomRightCorner(customCutCornerTreatment)
.setBottomRightCornerSize(new RelativeCornerSize(0.5f))
.build());
Just a note about new RelativeCornerSize(0.5f): It changed in 1.2.0-beta01. Before it was new RelativeCornerSize(50)).
I have a calendar that looks like this:
The Class that draws this Calendar is called MonthView and is a TableLayout:
class MonthView extends TableLayout{...}
The function that creates the calendar is shown below:
TextView btn;
TableRow tr;
void DisplayMonth(boolean animationEnabled){
...
for(int i = 0; i < 6; i++){
if(day > cal.getActualMaximum(Calendar.DAY_OF_MONTH))
break;
tr = new TableRow(context);
tr.setWeightSum(0.7f);
for(int j = 0; j < 7; j++){
btn = new TextView(context);
...
}
}
The function that changes the color of the background day is below:
public void changeBackgroundDay(List<Class> classes){
for(int i = 0; i < getChildCount; i++){
TableRow row = (TableRow)getChildAt(i);
for(int j = 0; j < row.getChildCount(); j++){
TextView t = (TextView)row.getChildAt(j);
for(int tam = 0; tam < classes.size(); tam++){
Class class = classes.get(tam);
// ---- THIS IS THE PART THAT I WANT TO CHANGE ----//
if(class.getTypePlanning().equals("null"){
t.setBackgroundColor(Color.parseColor("#777777");
}
else if(class.getTypePlanning().equals("R")){
t.setBackgroundColor(Color.parseColor("#2477B2");
}
// -----------------------------------------------//
...
}
}
}
}
I want to, instead of just changing the background color of the TextView, draw 4 circles on this TextView. In some cases, it can be drawn just 2 or 3. For example, like is shown in the pictures:
I've tried to make a Layer list with items that contains shape and color and defined this Layer list as the background of the TextView, but it didn't work really well.
The Layer list xml is below:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layerlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<item android:id="#+id/itemnaoplanejado"
android:bottom="1dp" android:right="1dp">
<shape android:shape="oval" android:visible="false">
<size android:width="2dp"
android:height="2dp"/>
<solid android:color="#777777"/>
</shape>
</item>
<item android:id="#+id/itemplanejado"
android:bottom="1dp" android:left="1dp">
<shape android:shape="oval" android:visible="false">
<size android:width="2dp"
android:height="2dp"/>
<solid android:color="#8CC9F3"/>
</shape>
</item>
....
</layer-list>
On the function changeBackgroundDay I do this:
public void changeBackgroundDay(List<Class> classes){
...
if(class.getTypePlanning().equals("null"){
LayerDrawable layerDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.layerlistday);
layerDrawable.findDrawableByLayerId(R.id.itemnotplanned).setVisible(true, false);
t.setBackground(layerDrawable);
}
}
Any ideas?
Thanks in advance.
Tyr this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/num_txt"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="0dp"
android:background="#drawable/bg_red"
android:gravity="center"
android:text="My name is NON"
android:textColor="#FFFFFF"
android:textSize="10dp" />
</RelativeLayout>
</RelativeLayout>
save in drwable bg_red.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="10dip"/>
<stroke android:color="#FF0000" android:width="5dip"/>
<solid android:color="#FF0000"/>
</shape>
Edited Code -----
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="#+id/num_txt"
android:layout_width="185dp"
android:layout_height="185dp"
android:layout_alignParentTop="true"
android:layout_marginTop="163dp"
android:background="#drawable/bg_red"
android:gravity="center"
android:text="My name is NON"
android:textColor="#FFFFFF"
android:layout_marginLeft="10dp"
android:textSize="10dp" />
<TextView
android:id="#+id/TextView02"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/TextView01"
android:layout_marginRight="90dp"
android:layout_marginTop="122dp"
android:background="#drawable/bg_red"
android:gravity="center"
android:text="My name is NON"
android:textColor="#FFFFFF"
android:textSize="10dp" />
<TextView
android:id="#+id/TextView01"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignTop="#+id/num_txt"
android:layout_toRightOf="#+id/num_txt"
android:background="#drawable/bg_red"
android:gravity="center"
android:text="My name is NON"
android:textColor="#FFFFFF"
android:textSize="10dp" />
</RelativeLayout>
I want to add badge notification to my arraylist.But I couldn't find a tutorial for this.This is my list code:
public void chatList() {
conversationsAdapter=new ArrayAdapter<JsonObject>(this,0) {
#Override
public View getView(int c_position,View c_convertView,ViewGroup c_parent) {
if (c_convertView == null) {
c_convertView=getLayoutInflater().inflate(R.layout.random_bars,null);
}
JsonObject user=getItem(c_position);
String name=user.get("name").getAsString();
String image_url="http://domain.com/profile/thumb/"+user.get("photo").getAsString();
TextView nameView=(TextView)c_convertView.findViewById(R.id.tweet);
nameView.setText(name);
ImageView imageView=(ImageView)c_convertView.findViewById(R.id.image);
Ion.with(imageView)
.placeholder(R.drawable.twitter)
.load(image_url);
return c_convertView;
}
};
ListView conversationsListView = (ListView)findViewById(R.id.conversationList);
conversationsListView.setAdapter(conversationsAdapter);
conversationsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
startChat(conversationsAdapter.getItem(position));
}
});
}
My list:
I want to add badge to this list.How can I do this ?
Ps:I found a library https://github.com/jgilfelt/android-viewbadger but I don't want to use it.
Inflate the layout in custom listview which extends base adapter instead of array adapter. Add following layout into the custom list item layout.
drawer_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#drawable/list_selector">
<ImageView
android:id="#+id/icon"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="#string/desc_list_item_icon"
android:src="#drawable/ic_home"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#id/icon"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#color/list_item_title"
android:gravity="center_vertical"
android:paddingRight="40dp"/>
<TextView android:id="#+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/counter_bg"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:textColor="#color/counter_text_color"/>
</RelativeLayout>
Use below drawable for background textview counter and set notification count value in textview
counter_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- view background color -->
<solid android:color="#color/counter_text_bg" >
</solid>
<!-- If you want to add some padding -->
<padding
android:right="3dp"
android:left="3dp" >
</padding>
<!-- Here is the corner radius -->
<corners android:radius="2dp" >
</corners>
</shape>
I have a drawable resource drawable/badge.xml which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<solid android:color="#000" />
</shape>
...and is used inside a layout file layout/badge.xml which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="18dp"
android:layout_height="18dp" >
<View
android:id="#+id/badge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/badge" />
<TextView
android:id="#+id/badge_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:textColor="#fff"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
Inside a BaseExpandableListAdapters getChildView method there is this code:
...
LinearLayout badgeContainer = (LinearLayout) convertView.findViewById(R.id.badge_container);
for (String property : properties) {
RelativeLayout badge = (RelativeLayout) inflater.inflate(R.layout.badge, badgeContainer, false);
badge.setLayoutParams(new LinearLayout.LayoutParams(50, 50));
((TextView) badge.findViewById(R.id.badge_text)).setText(course.property);
badge.findViewById(R.id.badge).getBackground().setColorFilter(getColorResourceByProperty(property), PorterDuff.Mode.DST);
badgeContainer.addView(badge);
}
...
So what I'm trying to do is change the background color of the drawable badge for each property, but this code still yields in all badges to have a black background. What am I doing wrong? I've also tried many other PorterDuff modes without results.
After fighting some more I got it working like this:
drawable/circle.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="#fff" />
</shape>
layout/badge.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/badge_text"
android:layout_width="16dp"
android:layout_height="16dp"
android:gravity="center_vertical|center_horizontal"
android:background="#drawable/circle"
android:textColor="#color/white"
android:textSize="12sp"
android:layout_marginLeft="1dp"
android:textStyle="bold" />
and inside the adapter:
LinearLayout badgeContainer = (LinearLayout) convertView.findViewById(R.id.badge_container);
for (int i = 0; i < course.properties.length; i++) {
TextView badge = (TextView) inflater.inflate(R.layout.badge, badgeContainer, false);
badge.setText(course.properties[i]);
int colorID = context.getResources().getIdentifier("property_" + course.properties[i], "color", context.getPackageName());
badge.getBackground().setColorFilter(context.getResources().getColor(colorID), Mode.MULTIPLY);
badgeContainer.addView(badge);
}
I want to highlight item clicked on custom listview. I tried different options but not of them are working. Can someone tell me what's wrong?
my custom listview com.foo.ViewEditListView extends ListView implements android.widget.AdapterView.OnItemLongClickListener
list_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView_list_info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
>
</TextView>
<EditText
android:id="#+id/searchQueryText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:drawableRight="#drawable/search"
android:hint="Search Expenses by Amount"
android:textColorHint="#5e8e19"
android:inputType="numberSigned|numberDecimal"
style="#android:style/TextAppearance.Small"
>
</EditText>
<com.foo.ViewEditListView
android:id="#+id/viewExpenseListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#/drawable/list_selector_bg" //doesn't work
/>
</LinearLayout>
list_row.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#/drawable/list_selector_bg" //doesn't work
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/v_row_field1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#C11B17"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="#+id/v_row_field2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textStyle="bold"
android:layout_marginRight="2dp" />
</RelativeLayout>
</LinearLayout>
list_selector_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true"
android:drawable="#android:drawable/list_selector_background" />
</selector>
I also tried to setSelector in Activity but none of them are working. Right now, i am clueless. Can someone help me here?
If i put android:background="#/drawable/list_selector_bg" into RelativeLayout, it highlights only that portion. But i want whole layout to be highlighted.
Thanks
CP
Have custom drawable set as background for the layout. Modify the below according to your needs. When pressed you will have different background and on release will return to the default state.
In your list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="#drawable/listbkg" // set backcground
android:orientation="vertical"
>
....
</LinearLayout>
listbkg.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/pressed" /> //pressed state
<item android:state_focused="false"
android:drawable="#drawable/normal" /> // normal state
</selector>
pressed.xml in drawable fodler
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FF1A47"/> //background color
<stroke android:width="3dp" // border color
android:color="#0FECFF"/>
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners android:bottomRightRadius="7dp" //for rounded corners
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
normal.xml in drawable folder
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/> // change olor
<stroke android:width="3dp" // for border color
android:color="#0FECFF" />
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners android:bottomRightRadius="7dp"// for rounded corners
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
Edit:
You can also include gradient as you can see the same in the snap shot.
In getView() of custom adapter
convertView =mInflater.inflate(R.layout.list_row, parent,false);
// inflating custom layout
Then in list_row.xml set the background for the root layout.
Resulting Snap Shot
When pressed it highlights the layout and on release will go back to normal state.
1) If you want highlight selected items you can handle it by using your CustomAdapter. But it's not very good way:)
2) I think, the best way is use common Android implementation of Checkable interface for your view (as example):
public class CheckableFrameLayout extends FrameLayout implements Checkable {
private boolean mChecked;
public CheckableFrameLayout(Context context) {
super(context);
}
public CheckableFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setChecked(boolean checked) {
mChecked = checked;
setBackgroundDrawable(checked ? new ColorDrawable(0xff0000a0) : null);
}
public boolean isChecked() {
return mChecked;
}
public void toggle() {
setChecked(!mChecked);
}
}
OR
3) Use CheckedTextView
You can found example in Android Samples named as ApiDemos (ListView with multichoice).
UPDATE:
Don't forget that your ListView must have ChoiceMode != ListView.CHOICE_MODE_NONE
Put CheckableFrameLayout into your package and rewrite your list_row.xml like this:
<com.foo.CheckableFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/list_selector_bg"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/v_row_field1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#C11B17"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="#+id/v_row_field2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textStyle="bold"
android:layout_marginRight="2dp" />
</RelativeLayout>
</com.foo.CheckableFrameLayout>
If you want get states for your CheckableFrameLayout from statelist (be setting it to background), then you need to override your list_selector_bg.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:drawable="#android:drawable/list_selector_background" />
</selector>
And rewrite CheckableFrameLayout for working with it. I have not done it correctly in haste (I don't know why it change highlight correctly only afer second tap). But you can take this code and improve it (maybe using code of CheckedTextView can help you):
public class CheckableFrameLayout extends FrameLayout implements Checkable {
private static final int[] CHECKED_STATE_SET = {
android.R.attr.state_checked
};
private boolean mChecked;
public CheckableFrameLayout(Context context) {
super(context);
}
public CheckableFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected int[] onCreateDrawableState(int extraSpace) {
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isChecked()) {
mergeDrawableStates(drawableState, CHECKED_STATE_SET);
}
return drawableState;
}
#Override
public void setChecked(boolean checked) {
mChecked = checked;
// setBackgroundDrawable(checked ? new ColorDrawable(0xff0000a0) : null);
}
#Override
public boolean isChecked() {
return mChecked;
}
#Override
public void toggle() {
setChecked(!mChecked);
}
}