drawable

Create drawable from bitmap

有些话、适合烂在心里 提交于 2019-12-23 07:02:12
问题 ALL, As suggested here I need to make a drawable out of my bitmap. But when I tried to use: Drawable d = new Drawable( my_bmp); it shows that this constructor is deprecated in favour of: Drawable(Bitmap bmp, int resourceId) How else I can make a drawable out of bitmap? Thank you. 回答1: You can use Drawable d = new BitmapDrawable(getResources(), my_bmp); A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream,

How to change Remote view Background in runtime

空扰寡人 提交于 2019-12-23 05:29:17
问题 I am trying to change the remote view background in runtime, I am using drawable xml to show customize notification. custom_notification.xml android:background="@drawable/layout_bg" android:layout_height="65sp" android:padding="10dp" > <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:drawableLeft="@id/layout" android:layout_marginRight="10dp" /> <TextView android:id="@+id/title" android

Set Background Drawable Resource from String

痴心易碎 提交于 2019-12-23 04:04:40
问题 I have looked everywhere but cannot find an example of programmatically setting a background resource from a string value? As an example: Drawable a = getResources().getDrawable( R.drawable.a ); Drawable b = getResources().getDrawable( R.drawable.b ); Drawable c = getResources().getDrawable( R.drawable.c ); abc.setBackgroundResource("b"); Is this possible or would I have to do it as a big switch statement? 回答1: you have getResources().getIdentifier for this purpose. It returns the id of the

How to Compare Two ImageViews?

99封情书 提交于 2019-12-23 03:03:20
问题 I want to check if two imageViews match or not , by getting their background from the Drawable . i did use this way : if (imgView1.getBackground().getConstantState() .equals(ContextCompat.getDrawable(getApplicationContext(),R.drawable.myImage) .getConstantState()) && imgView2.getBackground().getConstantState() .equals(ContextCompat.getDrawable(getApplicationContext(),R.drawable.myImage) .getConstantState())) { // do something } it works great on API 23 and API 24 , but not working with API 21

Android using Drawables in an Enum

*爱你&永不变心* 提交于 2019-12-22 09:59:28
问题 I have a project that I have to design an array of coins and work with it. My GUI looks like this - http://i.imgur.com/eRzN3Sb.png I want to be able to load the appropriate image from the coinArray for each coin. basically i want to be able to say coinView.setBackgroundResource(coinArray[x].image) i assume i need to somehow use a drawable object and i was hoping its possible to include it in my enum class. the enum class looks like public enum Currency { Penny(1), Nickel(5), Dime(10), Quarter

Crop Drawable to Square

落花浮王杯 提交于 2019-12-22 08:54:49
问题 I have a drawable that I have resized to the appropriate desired height (25dp), and the width is scaled proportionally. However, I want an image that is square, with a width of 25dp as well. However, I do not want to distort the image, so I am looking to to crop equal portions of the right and left of the drawable to give me the center 25dpx25dp. Is this possible? How? I have been trying for the past two hours and I'm about ready to throw in the towel... 回答1: Bitmap target= Bitmap

Using parents for drawable resources

a 夏天 提交于 2019-12-22 03:51:21
问题 When I define a style, it can be inherited from a parent style, e.g: <style name="DialogNoTitle" parent="@android:style/Theme.Dialog"> <item name="android:windowNoTitle">true</item> </style> Now I want to do the same with drawable resources, something like this: <shape xmlns:android="http://schemas.android.com/apk/res/android" name="ChildDrawable" parent="@drawable/ParentDrawable"> <solid android:color="@android:color/white"/> <corners android:radius="6dp"/> </shape> Is there a way to

Text with shapes in drawable resource

为君一笑 提交于 2019-12-22 03:35:09
问题 Can i create text-shape in drawable resource? I was googling much but found nothing... Here is my drawable file: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="oval"> <stroke android:width="3dp" android:color="#QQffQQ"/> <size android:width="120dp" android:height="120dp"/> </shape> </item> <item android:right="59dp" android:left="59dp"> <shape android:shape="rectangle"> <solid android:color="£22££20"/

ResourcesNotFoundException when resource available (API 22 and 23 devices)

强颜欢笑 提交于 2019-12-22 00:23:33
问题 I get this crash only on API 22 and 23 devices. (android.content.res.Resources$NotFoundException: File res/drawable/show_empty_state.xml from drawable resource ID #0x7f080156 at android.content.res.Resources.loadDrawableForCookie(Resources.java:2640) at android.content.res.Resources.loadDrawable(Resources.java:2540) at android.content.res.Resources.getDrawable(Resources.java:806) at android.content.Context.getDrawable(Context.java:458) at android.support.v4.content.ContextCompat.getDrawable

Drawable folders for different screen size and density combinations

∥☆過路亽.° 提交于 2019-12-21 19:22:17
问题 What would be the drawable folders for low density,medium screen low density,large screen low density,Xlarge screen medium density,small screen medium density,large screen medium density,Xlarge screen and for tablets? 回答1: low density,medium screen drawable-ldpi low density,large screen drawable-large-ldpi low density,Xlarge screen drawable-xlarge-ldpi medium density,small screen drawable-small-mdpi medium density,large screen drawable-large-mdpi medium density,Xlarge screen drawable-xlarge