我想将自定义图标输入到导航栏中的菜单中.但是,当我运行应用程序时,它只显示图标的阴影.如何正确显示图像?
这是菜单activity_main_drawer.xml的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/recent_picture"
android:icon="@mipmap/ic_recent"
android:title="Import" />
<item
android:id="@+id/nav_gallery"
android:icon="@drawable/ic_menu_gallery"
android:title="Gallery" />
<item
android:id="@+id/nav_slideshow"
android:icon="@drawable/ic_menu_slideshow"
android:title="Slideshow" />
<item
android:id="@+id/nav_manage"
android:icon="@drawable/ic_menu_manage"
android:title="Tools" />
</group>
</menu>
Run Code Online (Sandbox Code Playgroud)
这是带有导航视图的xml布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
在values文件夹中找到另一个drawables.xml文件.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<item name="ic_recent_picture" type="drawable">@mipmap/ic_recent</item>
<item name="ic_menu_gallery" type="drawable">@drawable/ic_menu_gallery</item>
<item name="ic_menu_slideshow" type="drawable">@android:drawable/ic_menu_slideshow</item>
<item name="ic_menu_manage" type="drawable">@android:drawable/ic_menu_manage</item>
<item name="ic_menu_share" type="drawable">@android:drawable/ic_menu_share</item>
<item name="ic_menu_send" type="drawable">@android:drawable/ic_menu_send</item>
Run Code Online (Sandbox Code Playgroud)
我已经四处寻找并且还没有找到正确的解决方案.在将本地文件夹引用添加到XCode项目后,我使用以下代码在iOS上显示图像显示图像没问题:
<Image style={styles.catimg} source={{uri: "imgs/1.png"}} />
Run Code Online (Sandbox Code Playgroud)
但是在Android上,我无法弄清楚在哪里放置图像以及如何在代码中引用它们.有人在android/app/src/main/res/drawable-hdpi中说过一个名为'drawable-hdpi'的文件夹,但如果在那里添加了这个文件夹,则构建失败.目前只有mipmap文件夹.
[免责声明:首先我知道有很多关于drawable和mipmap文件夹的帖子,我读了一堆血统]
从"Android编程 - 大书呆子牧场指南"一书中可以看出,我必须在一些文本旁边插入一个图标Button
.对于更高分辨率的屏幕,包含多个尺寸的图标是有意义的.在他们的解决方案中,他们将所有图像放在许多不同的Drawable文件夹中,并且图像的分辨率大小不同.
我通过在很多试验和错误之后将图标放在drawable文件夹中来使它在mipmap文件夹中工作,从而使它工作:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/next_button"
android:text="@string/next_button"
android:drawableRight="@drawable/arrow_right/"/>
Run Code Online (Sandbox Code Playgroud)
但是,我对它的工作方式感到困惑:
从这里我得到了一些困惑:
mipmap文件夹仅用于放置应用程序图标.
那是什么意思?从谷歌翻译我得到:
icon:程序,选项或窗口的屏幕上的符号或图形表示,尤指用于选择的几个中的一个.
我正在尝试向我的 Android 应用程序添加启动器图标,但安装应用程序时的分辨率似乎有问题。我正在使用的设备具有 XHDPI 屏幕,因此我正在使用 96x96 (px) 图像进行测试。我使用Android Studio中的Image Asset生成默认图标:
您会注意到图像有点模糊,因为它已调整大小。我制作的每个图标都会发生这种情况。怎么了?我正在使用 MIUI,尽管它似乎不会影响其他图标。
编辑:我的启动器图标位于 mipmap 文件夹内。
正如文档所述,启动器图标为48*48dp.
所以我认为我的nexus 5上的启动器图标应该是144*144px.
但是我研究了我的nexus 5的截图,我发现它几乎是166*163px.
为什么它比144*144px更大?
(ps在drawable-xxhdpi文件夹中带有144*144px图标的应用程序在启动器中也会显示166*163px.)
这是我的截图:
我最近又向Android Studio安装了一个Android SDK,SDK版本4.4(API级别19),在我的项目中使用它之后,它mipmap
在项目的res
文件夹(res/mipmap
)中添加了一组文件夹.
我既不明白为什么,也不知道如何使用它们.
mipmap文件夹仅用于放置应用程序图标.您使用的任何其他可绘制资产应像以前一样放在相关的可绘制文件夹中.
根据谷歌的这篇博文:
最好将应用程序图标放在mipmap文件夹(而不是drawable文件夹)中,因为它们的分辨率与设备的当前密度不同.
我仍然没有理由这样做.
为什么我们不能将应用程序图标也放在res/drawable
文件夹中呢?
此外,如果只应在应用程序图标中放置应用程序图标mipmap
,如何创建其他可绘制资源并drawable
使用Android Studio图像资源向导将它们放在文件夹中?(通过右键单击项目,选择New> Image Asset)进行访问
要使用 FCM 设置默认图标,我们可以在 Android 清单中添加元标记。我的目前如下所示,因为我想在接收推送通知时使用应用程序的图标作为通知图标:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_logo_launcher" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
Run Code Online (Sandbox Code Playgroud)
请注意,我是ic_logo_launcher.png
从 mipmap 文件夹获取的。这是可取的吗?
android android-notifications firebase firebase-cloud-messaging android-mipmap