I want to keep my app as close to the devices original theme as possible. Therefor I use this layout for my separators:
This is spored in a separate layout file. Isn't there anyway to use the same resource programmatically?
I've tried with:
TextView tvSeparator = new TextView(context);
tvSeparator.setBackgroundResource(android.R.drawable.list_selector_background);
But I don't know the padding, the font size, the font style etc from this :/
You must use the
context.getResources().getDrawable(R.id.xxx);
(Might differ, just remembering from my head..)
Since the resource you are using is the android.R resources, what you can do is this:
The list_selector_background.xml file will be there in your android SDK (where ever you have downloaded it). Look for it, copy the contents of this file in a new file called my_list_selector_background.xml in your resources folder (where all the other layout files are present)
Change whatever you want to change in it - padding, font-size, anything.
Now access this resource from your R instead of Android.R ..
so the code would now look like:
TextView tvSeparator = new TextView(context);
tvSeparator.setBackgroundResource(R.drawable.my_list_selector_background);
Note however that you cannot change the original list_selector_background.xml
I sovled it by just inflating android.R.layout.preference_category since that is a textfield
Related
I have made a new value resource file in the android studio project as name dimens
but while referring to it from XML I have to use the attribute #dimen
I am really curious to know the referring tag must have to be the same as the file name but it is not.
I have seen the same pattern in strings and colors.
But it is like that? any clue?
name of your files doesn't matter in fact, you can rename dimens.xml to anything.xml. Or you can have dimen_activity.xml and dimen_fragment.xml files, which helps you manage them. Also, you can keep in this file <dimen tags, but also <integers and any other (e.g. you can have one sizes.xml file). Resources are built upon content inside all XML files placed in values, a kind-of map is created then and all <dimens from all XML files are available under #dimen/ or R.dimen.
Hy,
I am using the next background colour #android:color/transparent for a ImageButton in the layout.xml. Could or should I externalize it in the colors.xml resources file?
Thanks
You could but it depends on your needs.
If you use that color in many different parts of your application it's best to place it in an external xml file. Sometimes you need to change the style of the whole application and it's easier to change the definition of that color instead of changing the color in many different places. If you're only using it in one single place then it is OK to leave it out of the external file.
EDIT:
<color name="my_background_color">#android:color/transparent</color>
I am new to android programming.I have started building an app using eclipse.In the layout file the app icon and App name comes there by default. How do I change it.
A relative layout is there by default.
Whatever I add say--image view textview get added below the main title bar.
How do I change this?
Links to app name and icon are placed in the AndroidManifest.xml inside the application tag. String resources, like #string/app_name, are placed inside the strings.xml file in the res/values directory. Drawable resources, like #drawable/ic_launcher, are inside the res/drawable set of directories. Good luck!
try This
For Logo
android:icon="#drawable/icon"
For Application Name android:label="#string/app_name"
As already pointed out by Egor, you must change the appropriate string in your strings.xml. Typically, the key name in the strings.xml is by default app_name. Change this to whatever you wish to change your App's name to.
For your App's icon, I would recommend using this website to create the appropriate resources: http://android-ui-utils.googlecode.com/hg/asset-studio/dist/icons-launcher.html. This saves the trouble of creating different size resources. It gives you all of them in on go. Once you have downloaded the new set of icons, just replace the old set of icons with the new set. Take care of the name though. Again, typically, the app icon has the name ic_launcher.
Simply U have to change in Androidmanifest File in application tag which include property like For change logo use android:icon="#drawable/icon" property and change drawable image as per your requirement and for change application name use android:label="#string/app_name" property and write at string.xml file in app_name label put appropriate name for that.
I am teaching myself Android using Eclipse, the Android plug-in, and Sams "Teach Yourself Android Development" book. I have this weird little problem. I've been able to create xml files in the res/values directory that hold strings and color values (colors.xml and strings.xml). I have been able to reference these values in the properties of my Android screens (the xml in res/layout), for example setting the "Text" and "Text color" properties with references like "#string/topTitle" and "#color/titleColor," where topTitle and titleColor are defined in the xml files.
BUT: when I create a file called "dimens.xml" and have font sizes in it, Eclipse correctly puts this file in res/values, but when I try to reference these values, e.g. "#dimension/titleFont" I get an error "No resource found that matches the given name." I've tried lots of different names, I've tried "#dimens" instead of the type, still nothing. If I go into the layout xml file and set it explicitly to a font size, e.g. 22pt, it works.
So Eclipse recognized my "dimens.xml" file when I made it well enough to put it in res/values, and lets me edit it, and shows it full of (dimension) values. It just doesn't recognize my referring to it in other xml files.
The book I'm using doesn't actually show a dimension example so I must be doing something wrong. I checked the Android docs but couldn't see any problem.
Any help appreciated. Thanks.
The correct way to refer to a dimension variable (stored in your dimens.xml (don't think the name here really matters though, it's what's inside that does)) from another xml file is like this:
"#dimen/nameOfVariable"
Notice that it is neither dimension, dimensions or dimens, but dimen!
If you look inside your xml file where you have your values, this will make sense as dimen is the name of the xml elements storing dimension values:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<dimen name="someDimension">5dp</dimen>
<dimen name="anotherDimension">10dp</dimen>
</resources>
I would like to have an app include a custom font for rendering text, load it, and then use it with standard elements like StaticText. Is this possible?
Yes you can, you jsut can't define it into xml layouts. You need to use it dynamically each time. Check this tutorial for instance.
In case link is dead, here is a sum up of the stuff :
Get a font file like times.otf
Drop it in your asset folder, inside a "fonts" folder
Get a reference of TextView with something like that:
TextView tv = (TextView) findViewById(R.id.myCustomTVFont);
Grab you font from the asset folder:
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/times.otf");
Make your TextView look great:
tv.setTypeface(tf);
As of Android 8.0 (API level 26), you can use fonts in XML. See the documentation here.
Your can take look in this thread as well to set custom fonts for all the views in your activity.