I am trying to set the name of my application and the name of my first activity to different values (I need trademark sign in my activity label, but not in the app name). I found this Naming my application in android and in the last comment the said if I set the app name using #string it will have affect, but it doesn't have. Is ther any way to do this?
On your onCreate()
String title = getTitle().toString();
setTitle(title + "(R)");
Being (R) the copyright symbol :)
AFAIK there is no way to achieve this in the manifest since the name attribute is used in the launcher automatically (I suggest that's what you mean with 'application name'). But you can do this in your code by simply using:
setTitle(R.string.yourActivityTitle)
-> The string in your manifest is used as "application name" and the string in your code is used for activity name.
Hope that helps...
Related
When I have to make a new string constant in a project I often use to simply write down the reference first just like: R.sring.my_new_string then I use Alt + Enter to pop up this dialog:
The problem is, as you can see only the default 'values' is selected when the dialog pops and I have to select the other 'values-it' (Italian strings) manualy to create the same string resource to that file too.
Of course this results in a deficient 'values-it/strings.xml' file because a lot of times I simply forget to select the checkbox.
Is there a way to somehow set Android Studio to always create the string resource for EVERY strings.xml in the project?
Thanks in advance
Press that to select all.
That doesn't solve your problem?
Happy coding!
I am new to android, I am trying to create a sample UI which is described in the developer.android website. When I add a edit text, I am getting that error message.
If you are currently using this: android:hint = "#string/edit_message", just do like that: android:hint = "edit_message". This is called hardcoded string. Its working, but its not recommended that you make strings this way. The other way is to go to resources, then to strings folder, and there should be one .xml, with strings. To make a new string, just copy the last one, change the name, and the content between >...<, where your string should be. To use that string you get it by its name. So if you name it "myStr", to use it in editText, you need to say: android:hint="#string/myStr" and you will get the content of the string. Hope this helps. Mark as answer if it does. Good luck.
Did you add the string resource?? To the left is package explorer. Select Your project and go to its res folder. In res folder select values and then click on strings.xml. Add your string resource there and save it. Then I dont think theres scope for such error messages.
I'm new to Android. When I add a button/views in Graphical layout it adds the label text this way- android:text="Button" . Why doesnt it add "android:text="#string/my_label" and add a string resource in string.xml file. Can't it be done automatically in eclipse?
I have searched a lot but I have not get any automated way to add a string to the resource file But This will save your time a lot IMHO.
Select a String, click Refactor --> Android --> Extract Android String.
Thanks to Brent Hronik. CTRL-1 on Windows works fine.
Because you don't have to use the #string resource. The purpose of the #strings resource is to make it easier to change elements about your code. For example, if you are using your application title in mutliple places, let's say in every dialog box, then if you change the title you would have to change it in all the instances that the app title is being display. So in this instance the #string/App_Title could be set to "My Program" and all of the dialog boxes can reference that. If you change the title to "Hello World" then all of these are changed. The #strings resource, while eclipse tries, doesn't have to be used for every string. Not using it is the equivalent to hard coding the value. There are plenty of reasons for and against using #string for everything.
I am not sure if there is a setting in eclipse that will automatically add a string to the resource file when the control is added.
(EDIT: Based on other users CTRL+1 is the short cut to do this.)
You can add the string to the strings.xml by clicking command and 1(on a mac, assume it would be control 1 on a Windows or Linux box) simultaneously. This will add the resource to strings.xml and then open that up in the editor.
Thanks Siddiq Abu Bakkar! I didn't think it would be there.
On Eclipse (and Windows) the shortcut is:
Alt+Shift+A (release all and then press) S
When you use Eclipse for first time it's not easy understand how to use these kind of "complex" shortcuts.
I can't vote and i can't comment answers yet (missing reputation as i'm a new user)
But i confirm :
1) hard type the string in your code like
mydlg.setTitle("hello guys");
2) select your string (e.g : "hello guys")
3) press Alt + Shift + A then press S
a dialog will appear to let you add a new string into resources. Everything should be already filled into that dialog box.
I created a wonderful app, but I want to rename the "application name" alone... (i.e the name seen by the user on the app icon ) .. ( this isn't package renaming)
How do I do it, without creating a new one ...
In the strings.xml file, there is an element app_name which is used in the AndroidManifest's application element as the app's name. Just change the value of app_name in the strings.xml file to change the name of your app.
You don't need to refactor to change the name that people see. That is set in your res->values->Strings.xml file. You can call it what you want.
you can try Refactor -> rename.
Some users want to rename my Android app to something else.
So I'd like to provide a text field for them to put in a new name inside my app.
Then how can I programmatically rename my app name to the new name?
You want to rename your app or change the title when application is running?
To change the title you have setTtle() funcion from activity.
If you want to change application name in string.xml you should have a value called app_name.
You have to rename it to the new value.
To do so you have to unzip the apk and modify the xml file and then repack it.
But making this way I think application have to be reinstalled.