I'm very new (second day!) to android and working my way through the dev guide. There, it says that you can reference attributes inside the current theme from your XML by using the form "?...", for example
<?xml version="1.0" encoding="utf-8"?>
<EditText id="text"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:textColor="?android:textDisabledColor"
android:text="#string/hello_world" />
If I try to build this, I just get "No resource found that matches the given name (at 'textColor' with value '?android:textDisabledColor')
Given that this seems pretty basic stuff, and yet I can't find any references to similar problems elsewhere, I must be missing something obvious or misunderstanding something simple. Can anyone tell me what it is?
I don't think textDisabledColor exists anymore - at least not in the newer SDKs which is probably why it can't be found. Try textColorSecondary instead - e.g.
android:textColor="?android:attr/android:textColorSecondary"
Unfortunately I cant figure out if theres a specific disabled color. I came across the site below which seems to define the default theme: See this link for definition of default theme
try android:textColor="?android:attr/textDisabledColor"
Related
I am new to Android development (just started today). I am familiarising myself with XML which is new to me. I would really appreciate it if people can help me understand this language.
Please see the XML code I am referring to below:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_super"
android:title="#string/action_search"
yourapp:showAsAction="ifRoom|withText" />
</menu>
Questions:
1) What is the best way to think of XML code? My understanding is that they are like trees. Should I think of it like the file systems where there are hierarchies etc?
2) I am not sure what the namespace usage is for. For example:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
does this mean that the menu tag contains xmlns:android attribute and a xmlns:yourapp attribute?
3)I would really like to learn how to use XML more proficiently, any links to resources will be much appreciated (I tried w3 but it really was not answering the questions I had.
4) What do the ":" mean/do. The rest of the code I understand. As the API explains it quite clearly but my basic understanding of XML is preventing me from fully understanding the code.
Questions:
1) What is the best way to think of XML code? My understanding is that they are like trees. Should I think of it like the file systems where there are hierarchies etc?
-- no xml is data tags so there are opening and closing tags and self contained flags like :
will discribe your fridge and if you have multiple dairy products and some veggies in the fridge it will look like this
<Fridge>
<Dairy>
<Milk />
<Cheese />
</Dairy>
<Veggies>
<Carrots />
<Pumpkin />
</Veggies>
</Fridge>
2) I am not sure what the namespace usage is for. For example:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
does this mean that the menu tag contains xmlns:android attribute and a xmlns:yourapp attribute?
so the xmlns is xml namespace and they are defined in schemas like a deffinition of what attributes there can be and namespaces combine a bunch of defined attributes like :
<menu xmlns:android ..
android:name=""
android:orderId="5"
/>
the android schema namespace describes all the attributes that android platform knows about and you can then access them but using android: and then the attributes that is known for that menu type
3)I would really like to learn how to use XML more proficiently, any links to resources will be much appreciated (I tried w3 but it really was not answering the questions I had.
the XML in android isn't XML that you would use elsewhere android only uses XML to describe how the screens and menus should look like and behave and the best place to learn more about how android uses xml is to look at developer.android.com and try to look at linear layout and learn from there
4) What do the ":" mean/do. The rest of the code I understand. As the API explains it quite clearly but my basic understanding of XML is preventing me from fully understanding the code.
the : in "that:this" is use this attribute from that namespace and the namespaces are defined with xmlns:NAMEDITWHATEVER="schema location"
NAMEDITWHATEVER:attribute1="what ever this attribute describes"
Yes, you can think of it as a nested structure, much like the tree of a file system
Yes, it means that menu has two of those attributes. For more information about namespaces, reference this post.
Without knowing what questions W3 didn't help you with, it's hard to tell what it is that you're looking for. XML is very straightforward. There isn't more to it than meets the eye.
The colon in foo:bar means that bar is in the foo namespace.
This is strange, yet I see it all the time as I have lots of reasons to display just a simple question mark in this app.
When editing with the Eclipse graphical layout editor, everything is fine...until I tell a TextEdit or a Button to display just a question mark. Here's my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/test_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/question_mark" />
</LinearLayout>
And the string is defined in res/values/strings.xml. The relevant line is:
<string name="question_mark">\u003f</string>
The error message I get is:
Missing styles. Is the correct theme chosen for this layout? Use the
Theme combo box above the layout to choose a different layout, or fix
the theme style references.
Couldn't find theme resource for the current theme
Change the text, and the error message goes away.
You can see that in my struggles, I'm even trying to use the unicode version of a question mark. And yes, \? doesn't work either.
Note that this only happens when the graphical layout editor is set to API 7 or greater.
Now the graphical layout editor displays the question mark properly, and the emulator and my phone display the question mark without any problems. I'm just annoyed with the error message taking up 1/4 of my screen for all my layouts (and obscuring other error messages that may crop up).
Any suggestions?
First, test this again on the ADT 21 release that shipped today.
If the problem continues, create a sample project that demonstrates the issue, and post it along with step-by-step instructions on the Android issue tracker.
Well, this is a really crappy hack, but it kind of works--if you stand on your head!
You can use the unicode \u00bf as in
<TextView
android:id="#+id/test_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\u00bf" />
It's not a normal question mark, but it's close enough for a hack and gets that annoying error message out of your hair. And it might even increase the humor quotient of your app!
But PLEASE, if anyone out there has a real fix, post it!
Wow, I entered a bug report...[time marches on]...finally, I get a few emails as the Google team starts to look at it.
Today, I received some good news. It looks like the bug has been fixed (and they found a few related bugs, which have been fixed as well). The fix will be in the next release, Version 21.1 Preview 2. You can read the official details here.
Looking forward to it!
First of all, I know there are thousens of post asking the same, but after few days looking for a valid answer and try everything I'm still having the same problem...
So let's expose my situation:
I'm using ABS + google maps, so my map view xml is the following:
<?xml version="1.0" encoding="utf-8"?>
<com.actionbarsherlock.internal.view.menu.ActionMenuItemView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ViewContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0PGmnrCR70lothfjc_sFGTdFtESQPOksYKQWYpw"
android:clickable="true" />
</com.actionbarsherlock.internal.view.menu.ActionMenuItemView>
Few days ago everything was good, I was able to do my stuff in the app and everything. But suddenly I just made a little change, insert a framelayout to display more options in the screen. I tried to go back but was impossible...
I'm really deseparated, what can I do? maybe I can create a new project and paste all my code, but not really sure if it's going to work...
Any suggestions?
BTW my error code is this one
Missing styles. Is the correct theme chosen for this layout?
Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.
Failed to find style 'mapViewStyle' in current theme
java.lang.NullPointerException
Exception details are logged in Window > Show View > Error Log
Thank you for your time!
I finally solve the problem, the error in the screen is still there, but just like a warining and when I execute the app same to work fine.
The only think I made, is change the specific layout of ABS and put a frame layout.
After taking a look at theming for Fede's UberMusic I came across the file album_screen.xml. Below is the source of that file. Basically I noticed that his themes have the ability to use custom views that are a part of his application, and that they have this XML namespace at the top theme. I am missing the connection as to how he is able to apply his attributes to views that he does not control, and how Eclipse will compile the cod below without fail. I placed the URL http://schemas.uberdroidstudio.com/theme into my browser's address bar but nothing came up, and I cannot figure out where/ how Eclipse knows the attributes that the namespace supports. Thank you ahead of time for your help.
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:theme="http://schemas.uberdroidstudio.com/theme">
<TextView
android:id="#id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
theme:textFilter="uppercase" /> <!-- This is the interesting line -->
I suspect that the theme:textFilter="uppercase" line isn't actually having an effect on the (apparently vanilla) TextView.
As for the URL of the namespace, it is interesting that you can't access it, since it does not appear to be a local styleable (Android would have you refer to a local styleable namespace as http://schemas.android.com/apk/res/your.package). +1 for novelty.
The solution is actually not as complicated as I originally thought. XML namespaces are arbitrary strings that just need to be unique. If your namespace does not start with http://schemas.android.com/apk/res then it is not validated and the APK package is not checked for declare-styleable or the like.
Now a custom namespace if very simple to implement, as illustrated by this code snippet in GitHub. Finally, applying custom XML attributes to "normal" widgets can be accomplished by using the LayoutInflater.Factory and calling setFactory before you inflate your views. Throw it all together and you have a highly theme-able, XML driven application like Fede's UberMusic.
I'm working on a couple of apps at the moment while I try to learn my way around the Android SDK. I had a bit of trouble recently with my layouts where I was defining, for example, an EditText element as such...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="#+id/price_per_pack"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/price_per_pack"
android:layout_alignParentLeft="true"
android:textSize="12pt"
android:text="Price Per Pack"/>
</LinearLayout>
The application was compiling correctly, however when I attempted to start the activity which utilizes this layout nothing would happen. Through a process of elimination I identified the id attribute as the troublesome one and while playing about I discovered that changing
android:id="#+id/price_per_pack"
to
android:id="#+android:id/price_per_pack"
solved my problem and the application behaved as expected. My initial attempt at declaring the id attribute was based upon examples in the SDK documentation so I'm wondering if somebody could explain to me why I needed to make the above change to get it working?
I'm sure that it won't make any difference but I'm developing using the android-mode.el emacs plugin and have a completely up-to-date copy of the SDK.
Thanks in advance.
From Android Documentation:
With the android package namespace in place, we're now referencing an ID from the android.R resources class, rather than the local resources class.
It looks like you might have some syntax errors in your code posted.