Posts

Showing posts with the label Android Drawable

Android Shape With Gradient Border And Shadow

Image
Answer : Here you go Create your layout <?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="match_parent" android:background="#c8c0c0" android:orientation="vertical"> <LinearLayout android:layout_width="120dp" android:layout_height="120dp" android:layout_centerInParent="true" android:background="@drawable/my_rectangle"> </LinearLayout> </RelativeLayout> Create my_rectangle.xml file inside drawable folder <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <gradient ...

Android GetResources().getDrawable() Deprecated API 22

Answer : You have some options to handle this deprecation the right (and future proof ) way, depending on which kind of drawable you are loading: A) drawables with theme attributes ContextCompat.getDrawable(getActivity(), R.drawable.name); You'll obtain a styled Drawable as your Activity theme instructs. This is probably what you need. B) drawables without theme attributes ResourcesCompat.getDrawable(getResources(), R.drawable.name, null); You'll get your unstyled drawable the old way. Please note: ResourcesCompat.getDrawable() is not deprecated! EXTRA) drawables with theme attributes from another theme ResourcesCompat.getDrawable(getResources(), R.drawable.name, anotherTheme); Edit: see my blog post on the subject for a more complete explanation You should use the following code from the support library instead: ContextCompat.getDrawable(context, R.drawable.***) Using this method is equivalent to calling: if (Build.VERSION.SDK_INT ...

Add Ripple Effect To My Button With Button Background Color?

Answer : Here is another drawable xml for those who want to add all together gradient background, corner radius and ripple effect: <?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorPrimaryDark"> <item android:id="@android:id/mask"> <shape android:shape="rectangle"> <solid android:color="@color/colorPrimaryDark" /> <corners android:radius="@dimen/button_radius_large" /> </shape> </item> <item android:id="@android:id/background"> <shape android:shape="rectangle"> <gradient android:angle="90" android:endColor="@color/colorPrimaryLight" android:startColor="@color/colorPrimary" ...