android-resources

Remove all unused resources from an android project

泄露秘密 提交于 2019-11-26 04:29:55
问题 I want to remove all unused layouts, strings, drawables, colors, etc from my Android res directory. Are there any tools that will give me a list of files and I can remove from my repository and elements within specifics files (e.g. unused string entries) that are no longer used? 回答1: You can easily search for unused resources from Android Studio. Just press Ctrl Alt Shift i and type " unused resources " (without quotes). That will execute lint. Super easy way to run lint commands (and other

setText fails to show a number as text in a TextView

心已入冬 提交于 2019-11-26 03:45:42
问题 I have 4 buttons and 1 TextView. I want each of the buttons to add or subtract a different amount from the value (parsed to int) in the TextView. When I click on one of the buttons it throws fatal errors (listed below). I\'ve searched some other Stackoverflow discussions and nothing seems to be working. Here is my current activity: public class PaydownSnowball extends Activity { int aAmt; String debtExtraPayment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate

Android how to get access to raw resources that i put in res folder?

泪湿孤枕 提交于 2019-11-26 03:38:30
问题 In J2ME, I\'ve do this like that: getClass().getResourceAsStream(\"/raw_resources.dat\"); But in android, I always get null on this, why? 回答1: InputStream raw = context.getAssets().open("filename.ext"); Reader is = new BufferedReader(new InputStreamReader(raw, "UTF8")); 回答2: For raw files, you should consider creating a raw folder inside res directory and then call getResources().openRawResource(resourceName) from your activity. 回答3: In some situations we have to get image from drawable or

How to fix: android.app.RemoteServiceException: Bad notification posted from package *: Couldn't create icon: StatusBarIcon

半腔热情 提交于 2019-11-26 02:18:46
问题 I\'m seeing the following exception in crash logs: android.app.RemoteServiceException: Bad notification posted from package com.my.package: Couldn\'t create icon: StatusBarIcon(pkg=com.my.package user=0 id=0x7f02015d level=0 visible=true num=0 ) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1456) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5487) at java.lang

About Android image and asset sizes

一笑奈何 提交于 2019-11-26 02:15:35
问题 I need to clarify some doubt about the image assets for my app, if I specify in an xml file that the height of something [image view] is 50 dip height which type of screen should i choose from the resources folder? drawable, hdpi, ldpi, mdpi, xhdpi, to have the 50 px height image, and what is the percentage for bigger, smaller size images compared to the base image, like in iOS, @2x, is literally 2 times the size of the image, and you say programatically the normal size, thanks! 回答1: mdpi is

how to get string from different locales in Android?

只谈情不闲聊 提交于 2019-11-26 02:09:26
问题 So I want to get the value of a String in several locales regardless of the current locale setting of the device/app. How should I do that? Basically what I need is a function getString(int id, String locale) rather than getString(int id) How could I do that? Thanks 回答1: NOTE If your minimum API is 17+, go straight to the bottom of this answer. Otherwise, read on... If you have various res folders for different locales, you can do something like this: Configuration conf = getResources()

Storing R.drawable IDs in XML array

℡╲_俬逩灬. 提交于 2019-11-26 01:57:01
问题 I would like to store drawable resources\' ID in the form of R.drawable.* inside an array using an XML values file, and then retrieve the array in my activity. Any ideas of how to achieve this? 回答1: You use a typed array in arrays.xml file within your /res/values folder that looks like this: <?xml version="1.0" encoding="utf-8"?> <resources> <integer-array name="random_imgs"> <item>@drawable/car_01</item> <item>@drawable/balloon_random_02</item> <item>@drawable/dog_03</item> </integer-array>

Is it possible dynamically to add String to String.xml in Android?

风格不统一 提交于 2019-11-26 01:55:48
问题 Is it possible to have placeholders in string values in string.xml that can be assigned values at run time? Example: some string PLACEHOLDER1 some more string 回答1: Formatting and Styling Yes, see the following from String Resources: Formatting and Styling If you need to format your strings using String.format(String, Object...) , then you can do so by putting your format arguments in the string resource. For example, with the following resource: <string name="welcome_messages">Hello, %1$s!

Passing image from one activity another activity

£可爱£侵袭症+ 提交于 2019-11-26 01:40:21
问题 There are similar questions on SO, but none worked for me. I want to fetch clicked image in Activity1 and display it in Activity2. I\'m fetching image id of clicked image like this: ((ImageView) v).getId() and passing it through intent to another activity. In 2nd activity, I use image id as following: imageView.setImageResource(imgId); I logged the value og image id in both the activities and it\'s same. But I\'m getting following exception: android.content.res.Resources$NotFoundException:

How do I get the resource id of an image if I know its name?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 00:46:33
问题 How do I get the resource id of an image if I know its name (in Android)? 回答1: With something like this: String mDrawableName = "myappicon"; int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName()); 回答2: You can also try this: try { Class res = R.drawable.class; Field field = res.getField("drawableName"); int drawableId = field.getInt(null); } catch (Exception e) { Log.e("MyTag", "Failure to get drawable id.", e); } I have copied this source codes from below URL.