Updated 22 December 2016
In this blog,
I will show you how to change some default style of android Views by programmatically.
In XML
1 2 3 4 5 6 7 |
<RatingBar android:id="@+id/ratingBar" style="?android:attr/ratingBarStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="start" android:gravity="center" /> |
In java
1 2 3 |
RatingBar ratingBar = (RatingBar) convertView.findViewById(R.id.ratingBar); LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable(); stars.getDrawable(2).setColorFilter(getResources().getColor(R.color.accent_color), PorterDuff.Mode.SRC_ATOP); |
getDrawable(index): Returns the drawable for the layer at the specified index.
Parameters index
The index of the layer must be in the range 0…getNumberOfLayers()-1.
PorterDuff.Mode.SRC_ATOP:
Consider these two images:
The effect is as if the destination image is trimmed to match the source image, and then held up in front of it:
The Porter/Duff operator that does this is called “Dest Atop”.
In this example, I have created a default Dialog view and change the blue line title divider in Dialog.
This is simple dialog,
1 2 3 4 |
Dialog dialog = new Dialog(ViewProductSimple.this); dialog.setContentView(R.layout.custom_dialog); dialog.setTitle("Custom Dialog"); dialog.show(); |
and change the title divider blue line,
1 2 3 4 |
int divierId = dialog.getContext().getResources() .getIdentifier("android:id/titleDivider", null, null); View divider = dialog.findViewById(divierId); divider.setBackgroundColor(getResources().getColor(R.color.line_color)); |
and custom_dialog.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/background_color" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:text="My Custom Dialog!!" android:textColor="@color/green_font_color" android:textStyle="bold" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:orientation="horizontal" android:paddingBottom="10dp" android:paddingTop="5dp"> <TextView android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:text="CANCEL" android:textColor="@color/green_font_color" android:textStyle="bold" /> <View android:layout_width="30dp" android:layout_height="match_parent"></View> <TextView android:id="@+id/btn_apply" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:text="SUBMIT" android:textColor="@color/green_font_color" android:textStyle="bold" /> </LinearLayout> </LinearLayout> |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.