android-drawable

What should i use for better performance, nine-patch or drawable xml resource?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 02:54:20
问题 What is the best way to set background for some view? For example 2 variants of backround: background with gradient, rounded corners and border background with just one color and rounded corners So which of variants would be better, nine-patch or drawable xml resource? 回答1: My guess is, NinePatch would be slightly faster in most cases. Here's what I found. GradientDrawable (the one used for rects in xml) uses this code to call through to Canvas which in turn uses native call leading to

How can I convert String to Drawable

孤街醉人 提交于 2019-11-27 01:59:18
问题 I have many icon in drawable folder and I have their name as String. How can I access to drawable folder and change background imageView (or any view) use these name in dynamically. Thanks 回答1: This can be done using reflection: String name = "your_drawable"; final Field field = R.drawable.getField(name); int id = field.getInt(null); Drawable drawable = getResources().getDrawable(id); Or using Resources.getIdentifier() : String name = "your_drawable"; int id = getResources().getIdentifier

Retrieve drawable resource from Uri

孤人 提交于 2019-11-27 01:50:46
问题 I'm storing the drawable resource path in an Uri in this way: Uri uri = Uri.parse("android.resource://my_app_package/drawable/drawable_name"); How do I get the Drawable that the uri is referencing? I don't want to put it in an ImageView, just retrieve the Drawable (or Bitmap) object. 回答1: getContentResolver cr object then call: is = cr.openInputStream(uri) and finally call: Drawable.createFromStream(InputStream is, String srcName) ...Here's an actual working code example so you can see for

Android Studio drawable folders

梦想与她 提交于 2019-11-27 01:43:32
问题 In Android Studio, I can't figure out where to put images to be used inside the app. The drawable folder isn't broken down into drawable-hdpi, drawable-ldpi, etc. I saw another question asking this and the answer was to switch to Project view instead of Android view but drawable is only one folder there too. There is mipmap-hdpi, mipmap-ldpi, etc, but people are saying that's only for app icons. I'm confused. 回答1: If you don't see a drawable folder for the DPI that you need, you can create it

Create a Bitmap/Drawable from file path

◇◆丶佛笑我妖孽 提交于 2019-11-27 00:59:46
I'm trying to create a Bitmap or Drawable from existing file path. String path = intent.getStringExtra("FilePath"); BitmapFactory.Options option = new BitmapFactory.Options(); option.inPreferredConfig = Bitmap.Config.ARGB_8888; mImg.setImageBitmap(BitmapFactory.decodeFile(path)); // mImg.setImageBitmap(BitmapFactory.decodeFile(path, option)); // mImg.setImageDrawable(Drawable.createFromPath(path)); mImg.setVisibility(View.VISIBLE); mText.setText(path); But setImageBitmap() , setImageDrawable() doesn't show an image from the path. I've printed path with mText and it looks like : /storage

Scale image keeping its aspect ratio in background drawable

杀马特。学长 韩版系。学妹 提交于 2019-11-27 00:40:22
问题 How do I make a background image fit the view but keep its aspect ratio when using <bitmap /> as a background drawable XML? None of <bitmap> 's android:gravity values gives the desired effect. 回答1: It is impossible to achieve manipulating background attribute within xml-files only. There are two options: You cut/scale the bitmap programmatically with Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter) and set it as some View 's background. You use ImageView

Android: Alternative for context.getDrawable()

孤者浪人 提交于 2019-11-27 00:12:34
问题 I have used context.getDrawable() like this in my project: Drawable greenProgressbar = context.getDrawable(R.drawable.custom_progressbargreen); But Eclipse is giving me an error that it needs a Minimum API level of 21 . This would mean after a quick google search my APP will only be usable on Android 5.0 . Since not all devices are using this version of android I would like to have an alternative for context.getDrawable() . 回答1: The previously accepted method has been deprecated, according to

Open-sided Android stroke?

拜拜、爱过 提交于 2019-11-26 23:49:41
Is it possible to create an Android shape object with stroke on only certain sides? Eg I have: <stroke android:width="3dip" android:color="#000000" android:dashWidth="10dip" android:dashGap="6dip" /> Which is similar to this CSS: border: 3px dashed black; How can I set the stroke on just one side? This is how I would do it in CSS: border-left: 3px dashed black; How do you do this in Android XML? I achieved a good solution with this one: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- This is the line --> <item android:top="

Add ripple effect to my button with button background color?

社会主义新天地 提交于 2019-11-26 23:24:51
I created a button and I want to add ripple effect to that button! I created a button bg XML file: (bg_btn.xml) <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFFFFF" android:endColor="#00FF00" android:angle="270" /> <corners android:radius="3dp" /> <stroke android:width="5px" android:color="#000000" /> </shape> And this is my ripple effect file: (ripple_bg.xml) <ripple xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:color="#f816a463" tools:targetApi=

android shape with bottom stroke

删除回忆录丶 提交于 2019-11-26 23:23:41
I need to create an android shape so that only the bottom has stroke (a dashed line). When I try the following, the stroke bisects the shape right through the center. Does anyone know how to get it right? the stroke needs to be the bottom line/border. I am using the shape as a background to a TextView. Please, never mind why I need it. <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="#1bd4f6" /> </shape> </item> <item> <shape android:shape="line" > <padding android