android-drawable

Open-sided Android stroke?

三世轮回 提交于 2019-11-26 08:49:36
问题 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? 回答1: I achieved a good solution with this one: <?xml version="1.0" encoding="utf-8"?>

Style bottom Line in Android

别来无恙 提交于 2019-11-26 08:42:31
问题 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\"

Get the ID of a drawable in ImageView

喜夏-厌秋 提交于 2019-11-26 08:26:45
I have one ImageView and set a drawable on it. Now I need to get the ID of the drawable on click event of ImageView dynamically. How can I get it? imgtopcolor = (ImageView) findViewById(R.id.topcolor); imgtopcolor.setImageResource(R.drawable.dr); // How do I get this back? Now on touch event of imgtopcolor i want to need drawable id because I am setting different drawable each time and want to compare the drawable with other Greg Giacovelli I think if I understand correctly this is what you are doing. ImageView view = (ImageView) findViewById(R.id.someImage); view.setOnClickListener(new

android:drawableLeft margin and/or padding

时光总嘲笑我的痴心妄想 提交于 2019-11-26 07:54:07
问题 Is it possible to set the margin or padding for the image which we added with the android:drawableLeft ? 回答1: As cephus mentioned android:drawablePadding will only force padding between the text and the drawable if the button is small enough. When laying out larger buttons you can use android:drawablePadding in conjunction with android:paddingLeft and android:paddingRight to force the text and drawable inward towards the center of the button. By adjusting the left and right padding separately

Vertical line using XML drawable

為{幸葍}努か 提交于 2019-11-26 06:56:07
问题 I\'m trying to figure out how to define a vertical line (1dp thick) to be used as a drawable. To make a horizontal one, it\'s pretty straightforward: <shape xmlns:android=\"http://schemas.android.com/apk/res/android\" android:shape=\"line\"> <stroke android:width=\"1dp\" android:color=\"#0000FF\"/> <size android:height=\"50dp\" /> </shape> The question is, how to make this line vertical? Yes, there are workarounds, such as drawing a rectangle shape 1px thick, but that complicates the drawable

How to change a layer-list drawable?

浪子不回头ぞ 提交于 2019-11-26 04:39:50
问题 Trying to learn some new things and can\'t figure this one out, any help is appreciated. Given this simple code which is right from Google\'s documentation: layers.xml: <?xml version=\"1.0\" encoding=\"utf-8\"?> <layer-list xmlns:android=\"http://schemas.android.com/apk/res/android\"> <item android:id=\"@+id/first_image\"> <bitmap android:src=\"@drawable/android_red\" android:gravity=\"center\" /> </item> <item android:id=\"@+id/second_image\" android:top=\"10dp\" android:left=\"10dp\">

Getting Bitmap from vector drawable

*爱你&永不变心* 提交于 2019-11-26 04:39:05
问题 In my application, I have to set a large icon for a notification. LargeIcon must be a Bitmap, and my drawables are vector images (the new feature in Android, see this link) The problem is when I try to decode a resource that is a vector image, I get a null returned. Here is the sample of code : if (BitmapFactory.decodeResource(arg0.getResources(), R.drawable.vector_menu_objectifs) == null) Log.d(\"ISNULL\", \"NULL\"); else Log.d(\"ISNULL\", \"NOT NULL\"); In this sample, when I replace R

How to add an image to the “drawable” folder in Android Studio?

☆樱花仙子☆ 提交于 2019-11-26 04:30:55
问题 I need to add an image to the res/drawable folder... When I choose new > image asset , it comes out a dialog to choose Asset Type ... How can I add an image to res/drawable folder? 回答1: For Android Studio 1.5 : Right click on res, new Image Asset On Asset type choose Action Bar and Tab Icons Choose the image path Give your image a name in Resource name Next->Finish Update for Android Studio 2.2 : Right click on res, new Image Asset On Icon Type choose Action Bar and Tab Icons On Asset type

How to define a circle shape in an Android xml drawable file?

☆樱花仙子☆ 提交于 2019-11-26 04:29:02
问题 I have some problems finding the documentation of the definitions of shapes in XML for Android. I would like to define a simple circle filled with a solid color in an XML File to include it into my layout files. Sadly the Documentation on android.com does not cover the XML attributes of the Shape classes. I think I should use an ArcShape to draw a circle but there is no explanation on how to set the size, the color, or the angle needed to make a circle out of an Arc. 回答1: This is a simple

Setting drawable folder to use for different resolutions

南楼画角 提交于 2019-11-26 03:49:48
问题 I have 4 different sizes for each of the icons I need to use in my app. The problem is My Nexus 7 (1280 x 800) and galaxy s2 (800 x 480) seem to use the resources in drawable-hdpi. How do I force the Nexus to use resources in drawable-xhdpi and then the 10 inch tab to use drawable-xxhdpi. I have this in my manifest file <supports-screens android:resizeable=\"true\" android:smallScreens=\"true\" android:normalScreens=\"true\" android:largeScreens=\"true\" android:xlargeScreens=\"true\" android