String Resource new line /n not possible?

use a blackslash not a forwardslash. \n <?xml version=”1.0″ encoding=”utf-8″?> <resources> <string name=”title”>Hello\nWorld!</string> </resources> Also, if you plan on using the string as HTML, you can use &lt;br /&gt; for a line break(<br />) <?xml version=”1.0″ encoding=”utf-8″?> <resources> <string name=”title”>Hello&lt;br /&gt;World!</string> </resources>

How can I get color-int from color resource?

You can use: getResources().getColor(R.color.idname); Check here on how to define custom colors: http://sree.cc/google/android/defining-custom-colors-using-xml-in-android EDIT(1): Since getColor(int id) is deprecated now, this must be used : ContextCompat.getColor(context, R.color.your_color); (added in support library 23) EDIT(2): Below code can be used for both pre and post Marshmallow (API 23) ResourcesCompat.getColor(getResources(), R.color.your_color, null); //without theme ResourcesCompat.getColor(getResources(), R.color.your_color, your_theme); //with … Read more

How to clear an ImageView in Android?

I used to do it with the dennis.sheppard solution: viewToUse.setImageResource(0); it works but it is not documented so it isn’t really clear if it effects something else in the view (you can check the ImageView code if you like, i didn’t). I think the best solution is: viewToUse.setImageResource(android.R.color.transparent); I like this solution the most cause … Read more

Gradle finished with non-zero exit value 1 (ic_launcher.png: error: Duplicate file)

According to Xavier Durochet’s explanation on G+, it’s due to one of the libraries you use having it’s own ic_launcher.png — which they of course should not (more on that at the bottom). Chances are the two icons mentioned in the log are different: one is yours and another one is most likely the generic … Read more

Get color value programmatically when it’s a reference (theme)

This should do the job: TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); @ColorInt int color = typedValue.data; Also make sure to apply the theme to your Activity before calling this code. Either use: android:theme=”@style/Theme.BlueTheme” in your manifest or call (before you call setContentView(int)): setTheme(R.style.Theme_BlueTheme) in onCreate(). I’ve tested it with … Read more