<selector> button states - Android Software Development

I am trying to figure out how to use the <selector> resource to change custom button images depending on the state of the button. I have created button_up.9.png, button_down.9.png, button_disabled.9.png and put them in the drawable folder.
I then created this button.xml file in the drawable folder:
Code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item
android:state_enabled="false"
android:drawable="@drawable/button_disabled" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/button_down" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/button_up" />
<item
android:state_enabled="true"
android:drawable="@drawable/button_up" />
</selector>
Eclipse does not like this xml file and spits out:
Code:
error: Found tag selector where item is expected
This seems to be how all the examples I have found define their selector xml file, what am I doing wrong?
Edit:
Eclipse is no longer giving me the error above but is giving me this error on the closing </selector>:
Code:
Multiple annotations found at this line:
- error: Error parsing XML: not well-formed (invalid
token)
- Content is not allowed in trailing section.

Ok, this is really strange. I just took the xml code I had pasted above and copied it over the same code in button.xml. This time it didn't give me any errors and I can now use the selector in my layout without a problem. Does anyone know why Eclipse would have been showing these incorrect xml errors?

Related

[Q] eclipse help

im working on a launcher app but have ran into a problem.
right now i am working on removing the title bar. in the res/values/ folder i have to create a styles.xml file containing this code: <?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
i put that code in but im getting an error on the last line saying: Premature end of line. Error parsing XML: element not found.
any ideas to why?

[GUIDE] Sense Language and Locale settings

Someone asked about how to change and edit the language settings for sense based roms, so I thought I'd write a small guide.
This seems to only work for Sense 2 roms
The language and locale settings for sense based roms have to do with the cid, which tells where the phone is from.
First off, we need to know your backup-cid, which can be found by putting:
Code:
dd if=/dev/block/mmcblk0p17 bs=1 count=8 2>/dev/null; echo
in either adb shell, or terminal emulator.
This will spit out an 8 character string, which will be something like "HTC__001"
Next, the cid files are stored in /system/customize/CID/ on the phone in xml format. They are not too hard to modify with a text editor, and you should be able to work out what values you want where.
Code:
<?xml version="1.0" encoding="utf-8"?>
<customization_form>
<category name="system">
<module name="locale">
<function>
<set name="single">
<item name="total_list">[COLOR="Red"]en_NZ;en_AU;en_GB;en_US;fr_FR;[/COLOR]</item>
<item type="boolean" name="[COLOR="Red"]en_NZ[/COLOR]">yes</item>
<item type="boolean" name="[COLOR="Red"]en_AU[/COLOR]">yes</item>
<item type="boolean" name="[COLOR="Red"]en_GB[/COLOR]">yes</item>
<item type="boolean" name="[COLOR="Red"]en_US[/COLOR]">yes</item>
<item type="boolean" name="[COLOR="Red"]fr_FR[/COLOR]">yes</item>
</set>
</function>
</module>
That is part of my modified cid.xml, the parts you want to change are in red.
Now, I don't know if we can just swap out the new cid.xml file, and re-run the setup after a reboot to get our language options.
What I did was create a flashable zip to replace the cid.xml file after installing a sense rom.
I have attached a zip, so you just open it up, and swap out the file in zip/system/customize/CID/ with a modified cid.xml, and then flash the zip after flashing a sense rom.
-Nipqer
Nipqer said:
Someone asked about how to change and edit the language settings for sense based roms, so I thought I'd write a small guide.
This seems to only work for Sense 2 roms
The language and locale settings for sense based roms have to do with the cid, which tells where the phone is from.
First off, we need to know your backup-cid, which can be found by putting:
Code:
dd if=/dev/block/mmcblk0p17 bs=1 count=8 2>/dev/null; echo
in either adb shell, or terminal emulator.
This will spit out an 8 character string, which will be something like "HTC__001"
Next, the cid files are stored in /system/customize/CID/ on the phone in xml format. They are not too hard to modify with a text editor, and you should be able to work out what values you want where.
Code:
<?xml version="1.0" encoding="utf-8"?>
<customization_form>
<category name="system">
<module name="locale">
<function>
<set name="single">
<item name="total_list">[COLOR="Red"]en_NZ;en_AU;en_GB;en_US;fr_FR;[/COLOR]</item>
<item type="boolean" name="[COLOR="Red"]en_NZ[/COLOR]">yes</item>
<item type="boolean" name="[COLOR="Red"]en_AU[/COLOR]">yes</item>
<item type="boolean" name="[COLOR="Red"]en_GB[/COLOR]">yes</item>
<item type="boolean" name="[COLOR="Red"]en_US[/COLOR]">yes</item>
<item type="boolean" name="[COLOR="Red"]fr_FR[/COLOR]">yes</item>
</set>
</function>
</module>
That is part of my modified cid.xml, the parts you want to change are in red.
Now, I don't know if we can just swap out the new cid.xml file, and re-run the setup after a reboot to get our language options.
What I did was create a flashable zip to replace the cid.xml file after installing a sense rom.
I have attached a zip, so you just open it up, and swap out the file in zip/system/customize/CID/ with a modified cid.xml, and then flash the zip after flashing a sense rom.
-Nipqer
Click to expand...
Click to collapse
ooohhh yeeees, it works great
thx
---------- Post added at 10:13 PM ---------- Previous post was at 10:06 PM ----------
Do you know how I can change the hardware keyboard language? Can I disable the spelling or set it to german?
I'm not sure exactly, but look under Language & Keyboard settings, and I think it's under the dafault soft keyboard settings that the Hardware keyboard settings are kept.
I'm running cyanogen at the moment, so this is only from memory for sense.
-Nipqer
Nipqer said:
I'm not sure exactly, but look under Language & Keyboard settings, and I think it's under the dafault soft keyboard settings that the Hardware keyboard settings are kept.
I'm running cyanogen at the moment, so this is only from memory for sense.
-Nipqer
Click to expand...
Click to collapse
thats not possible, I can only select englisch ...
should I delete some files with the rootexplorer , under system/usr .. ?

How to correct change APK background

hello everybody
I have a problem
I want change my apk background but have trouble
i edit style.xml
original
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RE_Main" parent="@*android:style/Theme.DeviceDefault.Light">
<style name="RE_Dialog" parent="@*android:style/Theme.DeviceDefault.Light.Dialog" />
</resources>
Change
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RE_Main" parent="@*android:style/Theme.DeviceDefault.Light">
<item name="android:background">@drawable/semc</item>
</style>
<style name="RE_Dialog" parent="@*android:style/Theme.DeviceDefault.Light.Dialog" />
</resources>
Can not be used after changing

[Q] Menu Icons with different themes

Hello,
in the settings of my App the users can switch between Holo.Light and Holo theme.
But I show some Menu options in the ActionBar. I've copied the icons for Holo.Light into my App.
When I switch to Holo theme, the icons looks not really good.
How can I implement the icons for the dark theme?
I've tried the following: http://stackoverflow.com/a/12339924
But it dont work..
values/attrs.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="main">
<attr name="search_icon" format="reference" />
</declare-styleable>
</resources>
values/styles.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Holo">
<item name="search_icon" [user=3944923]@drawab[/user]le/ic_action_search</item>
</style>
<style name="MyTheme.Light" parent="android:Theme.Holo.Light">
<item name="search_icon" [user=3944923]@drawab[/user]le/ic_action_search_light</item>
</style>
</resources>
menu/main.xml
Code:
<item
android:id="@+id/action_search"
android:icon="?search_icon"
.....
manifest:
Code:
<application
android:theme="@style/MyTheme"
wheres the error? it does always show the @drawable/ic_action_search_light icon..

AndroidManifest.xml Issue

I have decided to start learning the development side of Android, and have started on develepor.android.com. I've been following the tutorials to build the first app on there, using Android Studio. I got it to work fine, up until following the Starting Another Activity part. I guess I changed something in AndroidManifest.xml, and it absolutely will not compile now. I've ran the code validator numerous times, tried to compile it, googled for awhile, and it seems I have what it's asking for, but obviously not. the AndroidManifest.xml is:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="schemas.android/apk/res-auto"
package="learning.application">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MyActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter> />
</activity>
<activity
android:name=".DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName=".MyActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="learning.application.com.MyActivity" />
</activity>
</application>
</manifest>
This produces an error:
Code:
Merging main manifest AndroidStudioProjects/learning.app/app/src/main/AndroidManifest.xml
Merging result:ERROR
AndroidStudioProjects/learning.app/app/src/main/AndroidManifest.xml:12:9-23:20 Error:
Missing 'name' key attribute on element activity at AndroidManifest.xml:12:9-23:20
AndroidStudioProjects/learning.app/app/src/main/AndroidManifest.xml:16:13-22:29 Error:
Missing one of the key attributes 'action#name,category#name' on element intent-filter at AndroidManifest.xml:16:13-22:29
AndroidStudioProjects/learning.app/app/src/main/AndroidManifest.xml:17:17-18:65 Error:
Missing 'name' key attribute on element action at AndroidManifest.xml:17:17-18:65
AndroidStudioProjects/learning.app/app/src/main/AndroidManifest.xml:20:17-21:71 Error:
Missing 'name' key attribute on element category at AndroidManifest.xml:20:17-21:71
AndroidStudioProjects/learning.app/app/src/main/AndroidManifest.xml:26:9-34:20 Error:
Missing 'name' key attribute on element activity at AndroidManifest.xml:26:9-34:20
AndroidStudioProjects/learning.app/app/src/main/AndroidManifest.xml:31:13-33:71 Error:
Missing 'name' key attribute on element meta-data at AndroidManifest.xml:31:13-33:71
AndroidStudioProjects/learning.app/app/src/main/AndroidManifest.xml Error:
Validation failed, exiting
I've tried putting the package name in the android:name="foo" for the activity, and can't seem to figure out what I'm missing, I've googled around, and can't figure this thing out....apparently I'm that talented to screw up right off the bat, or not googling/understanding this? Can anyone show me what I'm missing?
**EDIT** Apparently it thinks that in the code is posting outside links, modified the top of AndroidManifest code so it'd let me post,
Figured it out, apparently, I changed the xmlns:android link to /apk/res-auto or something like that, when it should've been /apk/res/android...I removed the /res part for some reason...fixed that issue, now onto a java error.

Categories

Resources