id within drawable within layout - android

Edit: My question is different because the answer referenced is not trying to access and modify the drawable (which is what my question is about), but it is just replacing the drawable.
I'm trying to change the color of a shape within a drawable within a layout within a button.
My question is: How do I access the id for the shape element programmatically?
Here is the drawable that contains the shape within a selector (It is called 'ic_mf_account_icon.xml'):
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/accountShape">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/btn_bg_normal" />
<corners android:radius="#dimen/programmatic_btn_corner_radius" />
</shape>
</item>
<item android:right="10dp" android:left="10dp" android:top="10dp" android:bottom="10dp" android:drawable="#drawable/ic_server"/>
</layer-list>
</item>
</selector>
Here is the layout that contains the drawable I just listed (The drawable is referenced in the Button at the top):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/FilesListItem" >
<FrameLayout style="#style/FilesListContent" >
<Button
android:id="#+id/icon"
android:layout_width="36dip"
android:layout_height="36dip"
android:background="#drawable/ic_mf_account_icon" />
<include layout="#layout/files_list_item_overlay" />
</FrameLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:paddingLeft="10dip"
android:singleLine="true" />
</LinearLayout>
<ImageButton
android:id="#+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:background="#null"
android:padding="#dimen/info_icon_padding"
android:src="#drawable/ic_info_grey_normal" />
</LinearLayout>
Here is where I'm trying to access the drawable. I can access the initial layout, but when I try to stem from there and access the drawable I get a null reference -- To note, This is within a fragments 'onCreateView(...)' function if that matters:
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_account_list, container, false);
FindView find = FindView.inView(view);
// AbsListView absListView = find.absList(android.R.id.list);
AbsListView absListView = view.findViewById(android.R.id.list);
absListView.setAdapter(arrayAdapter = new BaseListAdapter<Account>(getActivity(), accounts) {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.fragment_account_list_item, parent, false);
View layoutView = convertView.findViewById(R.id.icon);
View drawableView = layoutView.findViewById(R.id.accountShape);
Drawable drawableBackground = drawableView.getBackground();
// From here I will endeavor to modify the drawables shape background.
Here is the code within the code just mentioned where I am trying to access the drawable from within the layout:
View layoutView = convertView.findViewById(R.id.icon);
View drawableView = layoutView.findViewById(R.id.accountShape);
Drawable drawableBackground = drawableView.getBackground();

Related

android autocomplettextview Resource not found - Resource is not a drawable

This issue is driving me crazy....
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f0100ab a=3}
at android.content.res.Resources.loadDrawable(Resources.java:2816)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.(View.java:3460)
at android.widget.TextView.(TextView.java:791)
at android.widget.EditText.(EditText.java:76)
at android.widget.AutoCompleteTextView.(AutoCompleteTextView.java:137)
at android.widget.AutoCompleteTextView.(AutoCompleteTextView.java:133)
my xml is :
<AutoCompleteTextView
android:layout_width="fill_parent"
android:layout_height="38dp"
android:id="#+id/idautoCompleteProfTextView"
android:background="#drawable/edittext" <---**drawable**...
android:layout_marginLeft="30dp"
android:layout_marginTop="0dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp"
android:paddingLeft="15dp"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="2dp"
android:textAlignment="center"
android:hint="#string/hint_signin_professional"
android:layout_below="#+id/btnAcceptSigninProf"
android:textColor="#000000"
android:dropDownVerticalOffset="5dp"
android:dropDownWidth="wrap_content"
android:inputType="textAutoComplete|textAutoCorrect"
android:popupBackground="#color/wallet_highlighted_text_holo_dark"/>
edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<corners android:radius="0dp"/>
<stroke android:width="2dip"
android:color="#ffffff" />
</shape>
Im inflating it as a fragment.
public class SigninProfessionalFragment extends Fragment {
public SigninProfessionalFragment(){}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_signin_professional, container, false);
...
I have not code-behind regarding the autocomplete because I just want to load it in my device and check layout,etc...
The problem should be in your theme, but not the code you posted.

Google Android ExpandableListView

How can I change the height indicator?
android:indicatorEnd and android:indicatorStart don't work?
<ExpandableListView
android:id="#+id/exListView"
android:groupIndicator="#drawable/indicator"
android:layout_width="match_parent"
android:layout_height="392dp"
android:indicatorLeft="250dp"
android:indicatorRight="300dp"
android:layout_weight="1.11"
android:indicatorEnd="10dp"
android:indicatorStart="15dp" />
You can do fully customized indicator with follow up these steps:
Set android:groupIndicator="#null"
<ExpandableListView
android:id="#+id/exListView"
android:groupIndicator="#null"
android:layout_width="match_parent"
android:layout_height="392dp"
android:layout_weight="1.11"/>
Define imageview consider as group_indicator into list_group_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:padding="8dp" >
<ImageView
android:id="#+id/group_indicator"
android:layout_width="30dip"
android:layout_height="40dip"
android:src="#android:drawable/arrow_down_float" />
<TextView
android:id="#+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dip"
android:gravity="center_vertical"
android:textColor="#f9f93d"
android:textSize="17dp" />
</LinearLayout>
Set group indicator image in your adapter according to isExpand() method
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);
ImageView groupIndicator = (ImageView) convertView.findViewById(R.id.group_indicator);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
if (isExpanded)
groupIndicator.setImageResource(android.R.drawable.arrow_up_float);
else
groupIndicator.setImageResource(android.R.drawable.arrow_down_float);
return convertView;
}
This is a customized way of implementation to achieve that what we want
It will help you completely!!
If it would be helpful to you then you can accept it.
this is efficient way to set indicator attributes settings_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_empty="true">
<layer-list>
<item
android:left="20dp"
android:right="-30dp"
android:top="120dp"
android:bottom="10dp"
android:drawable="#drawable/arrow_down">
</item>
</layer-list>
</item>
<item android:state_expanded="true">
<layer-list>
<item
android:left="20dp"
android:right="-30dp"
android:top="120dp"
android:bottom="10dp"
android:drawable="#drawable/arrow_up"
>
</item>
</layer-list>
</item>
Used into:
<ExpandableListView android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:groupIndicator="#drawable/settings_selector"
/>

Android style/shade properly ListItem layout

I have an app which uses a ListFragment. I want to style my own ListItem layout but don't know how to get desired effect. I want to it to look something like this:
I want that big imageView, little shaded stripe with TextView and Like button. Any ideas how to solve this ? especially that shading part.
You will need to set an adapter to your ListFragment using setListAdapter(adapter).
You can create your own adapter implementing BaseAdapter.
Then you override getView like this:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
CompleteListViewHolder viewHolder;
if (convertView == null)
{
LayoutInflater li = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.listitem, null);
}
ImageView image = (ImageView)v.findViewById(R.id.image);
TextView text = (TextView)v.findViewById(R.id.text);
... add the like button etc
return v; }
listitem.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/FrameLayout1"
android:layout_width="200dp"
android:layout_height="200dp" >
<ImageView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/someImage" />
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:orientation="vertical"
android:background="#drawable/gradient" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some text" />
<Button
android:id="#+id/likeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Like" />
</LinearLayout>
</FrameLayout>
gradient.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#00000000"
android:startColor="#FF000000"
android:type="linear" />
<corners
android:radius="0dp"/>

How to add badge to list

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>

Implement Divider between the last item of the child and next Groupheader expandableListview

I have implemented expandablelistview in android app and also implemented divider in it.
I have one problem in not getting the divider between the last item of the child and next group header.
Following image is how I want :
But following is what I'm getting:
Here if you compare both images the divider between the CID and About Set is not coming how to implement that divider ?
Also the groupIndicator is not changing inspite of providing the xml in the groupindicator containing the item tag with 2 different images in android:state_expanded and android:state_empty.
But the property of android:state_expanded and android:state_empty doesn't appear.
It's very easy to Implement.
1- We will add divider in groub_item_layout and child_item_layout:
group_item_layout :
<?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="wrap_content"
android:background="#color/white"
android:minHeight="50dp"
android:orientation="vertical">
<View
android:id="#+id/adapter_divider_top"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#B6B6B6" />
<TextView
android:id="#+id/tv_adapter_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingBottom="10dp"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:text="Home"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/primary_text" />
</LinearLayout>
child_item_layout :
<?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="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tv_adapter_desc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#212121" />
<View
android:id="#+id/adapter_divider_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/divider" />
</LinearLayout>
2- In your Adapter getChildView() and getGroupView() Methods:
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View view, ViewGroup viewGroup) {
if (view == null) {
view = mInflater.inflate(R.layout.group_item_layout, null);
mGroupViewHolder = new GroupViewHolder();
mGroupViewHolder.tvTitle = (TextView) view.findViewById(R.id.tv_adapter_title);
mGroupViewHolder.dividerTop = view.findViewById(R.id.adapter_divider_top);
view.setTag(mGroupViewHolder);
} else {
mGroupViewHolder = (GroupViewHolder) view.getTag();
}
// That if you want to show divider in expanded group only.
// If you want to show divider in all group items remove this block.
if (isExpanded) {
mGroupViewHolder.dividerTop.setVisibility(View.VISIBLE);
} else {
mGroupViewHolder.dividerTop.setVisibility(View.INVISIBLE);
}
// That if you want to show divider in expanded group only.
String myTitle = getGroup(groupPosition);
if(myTitle != null) {
mGroupViewHolder.tvTitle.setText(myTitle);
}
return view;
}
#Override
public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, final ViewGroup parent) {
if (view == null) {
view = mInflater.inflate(R.layout.child_item_layout, null);
mChildViewHolder = new ChildViewHolder();
mChildViewHolder.tvDesc = (TextView) view.findViewById(R.id.tv_adapter_desc);
mChildViewHolder.dividerBottom = view.findViewById(R.id.adapter_divider_bottom);
view.setTag(mChildViewHolder);
} else {
mChildViewHolder = (ChildViewHolder) view.getTag();
}
if(isLastChild) {
mChildViewHolder.dividerBottom.setVisibility(View.VISIBLE);
} else {
mChildViewHolder.dividerBottom.setVisibility(View.INVISIBLE);
}
Timesheet timesheet = getChild(groupPosition, childPosition);
if(timesheet != null) {
mChildViewHolder.tvDesc.setText(timesheet.getDescription());
}
return view;
}
Hope this helps anyone.
Instead of using ExpandableListView's divider, you can make your own. Set the background of the lists's parent elements to
android:background="#drawable/top_divider"
Where drawable/top_divider.xml contains
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="-1dp" android:right="-1dp" android:bottom="-1dp">
<shape>
<solid android:color="#android:color/transparent" />
<stroke android:width="1dp" android:color="#android:color/black" />
</shape>
</item>
</layer-list>
Firstly make custom expandable listview...
then add different divider to header and its child
Refer the code(header of expandable listview xml):-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#000000" >
<ImageView
android:id="#+id/divider_top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/divider_vertical" />
<TextView
android:id="#+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/divider_top"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textColor="#c5e26d"
android:textSize="17dp" />
<ImageView
android:id="#+id/divider_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/lblListHeader"
android:layout_centerHorizontal="true"
android:background="#drawable/divider" />
</RelativeLayout>

Categories

Resources