Selector does not work with mipmap image in android

那年仲夏 提交于 2020-01-17 03:20:19

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/35082678/selector-does-not-work-with-mipmap-image-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!