All I want is that an imagebutton which changes to another image when user press the button on. Following is my directory list. As you see I don't have drawable-hdpi, drawable-mdpi ..and others. And also I can't see mipmap-hdpi, mipmap-mdpi ..and others. My problem is I can't add selector xml for my imagebutton.
directory list
Following image is my content_main file which known as activity_main.
content_main.
My program shows the image of button but when I add android:background="#drawable/fbpressed" code piece in content_main, the program fails. it says unfortunately Login2 has stopped!
I tried lots of combination for my selector file which is fbpress.xml. like I tried android:icon="#mipmap/facebook_pressed" but it fails again and again. any idea?
Please change you selector:
<selector>
<item android:drawable="#mipmap/facebook_press" android:state_press="true">
<item android:drawable= "#mipmap/fracebook">
</selector>
Please click the Android in you screenshot , and change it to Project.It can be more clear.
Yes guys I've solved the problem. I did not know that i should change my values/styles.xml file if i add an resource file into my button. (which is fbpress.xml)
Also I changed my folder representation from Android style to Project style so that i can see my mipmap-hdpi, mdpi etc.
change from android to project
I add those lines into my styles.xml. fbpress is my resource file which is selector file.
<style name="fbpressed" parent="#android:style/Widget.Button">
<item name="android:background">#drawable/fbpressed</item>
</style>
Following is my part of content_main.xml. I added android:background="#drawable:fbpressed" and style="#style/fbpressed" lines into this file.
imageButton
And finally my button works =) Thanks for all your helps
Related
I am trying to implement a splash screen for my application, following the usual method; defining a new theme inside the styles XML file that places a drawable as windowBackground and reverting to the main theme in the Activity's onCreate().
However, I am having problems when showing the logo I developed in Photoshop: I exported it as a 144x144 PNG file, created an Image Asset with it (replacing the standard ic_launcher drawable) but when I try to visualize it inside an XML file, this image is displayed instead
Screenshot
Any ideas? I've also tried to create a vector asset from the .psd but nothing is shown either...
https://romannurik.github.io/AndroidAssetStudio/
use this link to generate your icon. It will work.
Change the code and so on
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/your_background"/>
<item android:drawable="#drawable/your_image">
</item>
</layer-list>
I've created a directory inside drawable directory which contains two icons "empty_star.png". Now how to give address of these icons in style.xml
i tried following:
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="drawable/icons/empty_star" />
<item android:drawable="drawable/icons/empty_star" />
but it shows error.
i also tried #drwable/icons/empty_star but still getting error.
Try this:
android:drawable="#drawable/empty_star"
The resources mechanism doesn't support subfolders in the drawable directory. You need to keep that hierarchy flat. Place your images in drawable folder and use it as android:drawable="#drawable/empty_star"
Can the Android drawable directory contain subdirectories?
According to the answer posted earlier, resource mechanism does not support sub folders in drawable folder. So you should maintain flat hierarchy.
I am trying to change the color of the little triangle on the Actionbar spinner (sherlock). I have done so using the following code:
<style name="MyTheme" parent="Theme.Sherlock.Light">
<item name="windowActionBarOverlay">true</item>
<item name="homeAsUpIndicator">#drawable/ic_drawer</item>
<item name="actionDropDownStyle">#style/MyActionBarSpinnerStyle</item>
</style>
<style name="MyActionBarSpinnerStyle" parent="#style/Widget.Sherlock.Light.Spinner.DropDown.ActionBar">
<item name="background">#drawable/actionbar_spinner_background</item>
</style>
The icon triangle is changed but it seems to stretch the image to the whole size of the spinner.
image http://dodsonsolutions.com/screens/screen1.png
I am using the patch-9 drawable file that everyone says to use:
spinner http://dodsonsolutions.com/screens/spinner_background_disabled.png
If this is not the correct dimensions of the file then does anyone know what it should be?
Or how do I get it not to stretch and just sit in the bottom right hand corner.
Thank you.
are you using the image that has correct extension?
check the extension of the png file you are using. if it is not ".9.png", change it into .9.png
or if it is .9.png?
there must be a build error of your project. try to rebuild & run. that must be solved.
1.try to define pixel in the area that you want to re-size not all around the image and check pixel more than 3 mostly declaring 1 pixel not working
2.check your xml file to make sure layout_width and layout_height is wrap_content
3.To use 9patch :the image file extension should be png and while you declare area extension become .9.png
whenever I try to apply a VERY simple style in eclipse I get errors:
the style is as below (filename styles.xml in res/layout)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="commonStyle">
<item name="android:background">#EEEEEE</item>
</style>
</resources>
Regardless of whether I try to apply this to a LinearLayout (using style="#style/commonStyle") or to an activity in my manifest file (using android:theme="#style/commonStyle") I ALWAYS get the error "No resource found that matches the given name...".
If I try to apply an Android theme to an activity (say Theme.Black) it works just fine.
If I remove any usage of my style, my R.java file is generated as normal with the following contents:
public static final int styles=0x7f030002; (in the generated layout class)
I have NO idea what is going on. It seems that NOONE is having the same troubles as me (Ive spent about 4 hours searching using google, and came up with not even a remotely close answer).
Ive tried restarting eclipse, clean building etc. etc. and nothing works what so ever...
So what am I missing?
Try moving your styles.xml file to res/values.
http://developer.android.com/guide/topics/resources/style-resource.html
Styles need to be stored in the res/values folder :)
http://developer.android.com/guide/topics/ui/themes.html (See Defining Styles)
The name of the XML file is arbitrary,
but it must use the .xml extension and
be saved in the res/values/ folder.
I haven't used styles in my code yet, however generally you need to use
android:
Does it work when you use this?:
<style android:name="commonStyle">
Please verify the you call the style in the correct manner :
for example this might compile but will not work :
style="mainButtonText"
this is the correct way to call style:
style="#style/mainButtonText"
I'm trying to set a tabhost selector, as i found an example demonstrating that i should create an xml file in drawable like this :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/hotel_selected"
android:state_selected="true" />
<item android:drawable="#drawable/hotel" />
</selector>
but when compiling, eclipse keep saying that it's an invalid start tag in this file.
please help me solve this.
many thanks.
Found a solution, I created the xml file by using a simple text editor (notepad++) and saved it to /res/drawable and compiled, result: it worked like a charm :)
Ideal solution should be to put the XML file in
/res/xml
i have came across the same error and than solved, i did mistake of adding the xml file under values folder so it was not able to recognise selector tag. i removed it from values folder and added inside the drawable folder and it worked without any error. this was in case of Xamarin.Android.
You can right click on the directory you want to create the XML file, selecect Android xml file, and then edit that file. This solved my issue.
Its seems that there is no any error.
There may be some problem. But you can do one thing, do Project -> Clean , it may resolve your issue.