选择器不适用于Android中的Mipmap图像 [英] Selector does not work with mipmap image in android

查看:169
本文介绍了选择器不适用于Android中的Mipmap图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是一个imagebutton,当用户按下该按钮时,该按钮会更改为另一个图像。以下是我的目录列表。如您所见,我没有drawable-hdpi,drawable-mdpi ..等。而且我也看不到mipmap-hdpi,mipmap-mdpi ..等。我的问题是我无法为我的imagebutton添加选择器xml。
目录列表
下图是我的content_main文件,即activity_main。
content_main。

我的程序显示了按钮,但是当我在content_main中添加android:background = @ drawable / fbpressed代码段时,程序将失败。它说不幸的是Login2已经停止!

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!

我为选择器文件fbpress.xml尝试了很多组合。就像我尝试了android:icon = @ mipmap / facebook_pressed一样,但是一次又一次失败。知道吗?

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?

推荐答案

是的,我已经解决了这个问题。如果将资源文件添加到按钮中,我不知道应该更改我的values / styles.xml文件。 (这是fbpress.xml)

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)

我也将文件夹表示形式从Android样式更改为Project样式,以便可以看到我的mipmap-hdpi,mdpi等。

Also I changed my folder representation from Android style to Project style so that i can see my mipmap-hdpi, mdpi etc.

从android更改为项目
我将这些行添加到我的styles.xml中。 fbpress是我的资源文件,它是选择器文件。

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>

以下是我的content_main.xml部分。我在此文件中添加了android:background = @ drawable:fbpressed和style = @ style / fbpressed行。
imageButton
最后,我的按钮有效=)感谢所有人您的帮助

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

这篇关于选择器不适用于Android中的Mipmap图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆