In my android project none of my #string variables are not working.
For example in the title bar I see #string/app_name instead of myapp.
In my AndroidManifest.xml it looks normal, with the line android:label="#string/app_name"
Also, in my layout buttons and textviews show #string/action_sign_in but they also have the line in there xml layout. android:text="#string/action_sign_in"
Anyone had this issue before?
Clean, rebuild verify if its working.
If not, you can alt+enter on the #string/action_sign_in redline and click on create string value resource then set the value to the string.
Related
1.) Is there any reason to have a default value inside an android xml layout?
Ex.) The TextView below has included a default value of
android:visibility="visible"
`<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="visible"/>`
Conjecture: Because this is a default value, it has no effect, and therefore is an unnecessary line of code in the XML file. Is that line of thinking correct?
2.) If there is no reason for default values to exist in Android xml files, is there a lint plugin available to point out default value code lines in android XML files?
It is my thought that a large number of code lines in XML files are default values, serving no purpose. What can we do to reduce these lines of code?
U can create a style with your default values and use it.
For example:
<style name="DefaultTextViewStyle">
<item name="android:visibility">visible</item>
</style>
to use this:
<TextView
style="#style/DefaultTextViewStyle" />
I had some hope that the Lint inspection Redundant default value attribute assignment for xml, run via Android Studio might have done what you're asking. You can run it as specified under the Manually Run Inspections part of the Android docs. i.e.Android Studio -> Analyze -> Run Inspection by name -> enter "Redundant default value attribute assignment", then select the scope for the Lint check.
Sadly though, it doesn't pick up the case you mention above. I'm just wondering if there's something I've missed, or if this isn't intended for Android xml in some way?
When reviewing my app, I noticed that the blue bar on the top and the text in the bar (the project name) does not fit in the app.
I tried changing the project name into a more relevant one by going into REFACTOR -> RENAME but it said 'can't rename root module.' every time I tried to.
Is there a way I can either delete the blue bar or change the text on it?
Are you familiar with the resources strings object? Let me know if this makes sense... Look at the image that I've included. Go to res/values/strings.xml and make the app_name tag be empty
<string name="app_name"></string>
Project name for Toolbar is defined in res/values/strings with key app_name by default.
In strings.xml, change app_name.
Or there's a setText method on the ActionBar class
To remove the bar depends on the theme used by that Activity (or if you explicitly show a Toolbar in the XML layout)
The name of your app is defined in your AndroidManifest.xml. Inside, you'll see an Application object, with a property of ApplicationName. Set this to whatever you want.
for remove top bar use in Manifest file :
<application ....
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
>
The title of the action bar (your blue bar on the top) is set inside you AndroidManifest.xml, inside the activity tag:
<activity
android:name=".activity.MainActivity"
android:exported="true"
android:label="#string/app_name" >
</activity>
A good practice is to refer to a string stored inside Strings.xml
<string name="app_name">My cool app</string>
getActionBar().setTitle("TITLE");
OR
getSupportActionBar().setTitle("TITLE");
So I'm building a game in Android, and I have just created a huge XML file. When I switch to graphical layout in ADT, I'm getting the right layout, so no problems there.
But below the graphical layout, There are two messages:
Couldn't resolve resource #drawable/ic_launcher
Couldn't resolve resource #string/app_name
I have no idea what is causing these problems, as both words ic_launcher and app_name are not found anywhere in my XML.
But I found ic_launcher in all *hdpi folder under res/drawable/ and the string app_name was in res/values/string.xml
Should I have entered XML tags somewhere inside my code? If so, can you please tell me under which tag it should be?
[My XML is composed entirely of nested LinearLayouts and Buttons]
Thanks!
Make sure you don't have errors in other resources (layouts, values, drawables, etc.).
And then clean/refresh/build the project
I have an imageView in my main.xml file, that isn't setup with a source initially. I want to be able to dynamically change the image resource within the code. so lets so i have my imageView setup like this:
<ImageView
android:id="#+id/countryImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/CountryImageContent"/>
So i try to access within my code like this:
ImageView img = (ImageView) findViewById(R.id.countryImage);
The problem is here. Eclipse is giving me an error saying that "countryImage cannot be resolved or is not a field". A quick peek into my R.java file is showing me that the imageView isn't actually in there. Why is this happening? Thanks.
look into your drawable and layout if there is any error
if not try cleaning your project
Go to Project > clean > select your project
if not then look into your imports for
your.packagename.R remove it
Project -> Clean.
That is the only solution to this.
Also make sure that among your import statements, you do not have this : import android.R
Check this link for a detailed procedure.
Note : I am assuming that there are no errors in your layout and drawable files, as errors in them may also lead to this problem.
make sure all resource files have only lowercase letters , numbers and the underscore character ("_") .
only if there are no errors in creating the R file (in the "gen" folder) , you can use the id of it.
I think it is the problem to giving the name of #string
Please Remove all UpperCase Character from #string/CountryImageContent and replace it with small character.
R.java file doesn't support any Uppercase character. It gives the same error when you declare the file name of any resources Like :- Image, XML, #string, etc...
Just rename CountryImageContent with country_image_content. it will work perfect.
Another option to try in this case is: File --> Invalidate Caches / Restart...
I've looked at several other questions related, one answer even seemed like it solved the problem however I was wrong.
The issue is I get:
Parser exception for C:\Documents and Settings\djordan\My Documents\SampleTest\AndroidManifest.xml: The markup in the document following the root element must be well-formed.
When I drag/drop a new TextView or Multiline Text view item to the canvas. All other Text Fields add fine.
EDIT: Pasted the wrong error ... updated. and Added following work flow:
1. open SDK, check API 16 installed.
2. open Eclipse, create new Android project
- name, target/minimum API 16
3. in Graphical Layout drag "Plain Text" or "MultiLine Text" from the Text Fields.
4. view error above.
Flip over to the xml page, go through and find the textView you just added. Find the attribute where it says android:textSize="18" and change it to android:textSize="18dip" That should solve it. The error is telling you that the units for that attribute are not valid or were not set.