android 相关问题

Android是谷歌的移动操作系统,用于编程或开发数字设备(智能手机,平板电脑,汽车,电视,磨损,玻璃,物联网)。对于与Android相关的主题,请使用特定于Android的标签,如android-intent,android-activity,android-adapter等。对于开发或编程以外的问题,但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。

Android Google Maps Sdk 显示空白灰屏

我的 Android 应用程序有 Google Maps Sdk 版本 18.2.0。 一切正常,直到 24 年 5 月 14 日,大约 50% 运行该应用程序的设备开始显示带有 Google 徽标的空白灰屏...

回答 1 投票 0

java.lang.IllegalStateException:CompositionLocal LocalLifecycleOwner 不存在

当我收集AsState()或collectAsStateWithLifecycle()时,我收到java.lang.IllegalStateException:CompositionLocal LocalLifecycleOwner not present错误。我不知道出了什么问题。这是以前的

回答 1 投票 0

推送通知统计

我正在通过主题使用 Firebase 推送通知。 有什么方法可以知道应用程序在后台是否收到通知,或者我如何知道哪些用户收到了通知,哪些用户没有收到通知(

回答 1 投票 0

Glide:将本地SVG文件加载到ImageView中

我有一个本地 SVG 文件,我想将其加载到我的图像视图中。 SVG 文件通过我们公司的集成机制提供给我的应用程序。换句话说,我无法通过...

回答 1 投票 0

Flutter Native Splash Screen 包导致应用程序无法在 Android 模拟器中运行

我试图将启动屏幕添加到我的 flutter 应用程序中,但是当我将“flutter_native_splash”依赖项添加到我的 pubspec.yaml 文件中时,我无法运行 android 模拟器。当我按 &...

回答 1 投票 0

AppCompat 工具栏上的菜单项着色

当我将 AppCompat 库中的可绘制对象用于工具栏菜单项时,着色会按预期工作。像这样: 当我将 AppCompat 库中的可绘制对象用于我的 Toolbar 菜单项时,着色会按预期工作。像这样: <item android:id="@+id/action_clear" android:icon="@drawable/abc_ic_clear_mtrl_alpha" <-- from AppCompat android:title="@string/clear" /> 但是,如果我使用自己的可绘制对象,或者实际上将可绘制对象从 AppCompat 库复制到我自己的项目中,它根本不会着色。 <item android:id="@+id/action_clear" android:icon="@drawable/abc_ic_clear_mtrl_alpha_copy" <-- copy from AppCompat android:title="@string/clear" /> AppCompatToolbar中是否有一些特殊的魔法只能为该库中的可绘制对象着色?有什么方法可以让它与我自己的绘图一起使用吗? 使用 compileSdkVersion = 21 和 targetSdkVersion = 21 在 API 级别 19 设备上运行此程序,并使用 AppCompat 中的所有内容 abc_ic_clear_mtrl_alpha_copy 是 abc_ic_clear_mtrl_alpha 中的 AppCompat png 的精确副本 编辑: 着色基于我在主题中为 android:textColorPrimary 设置的值。 例如<item name="android:textColorPrimary">#00FF00</item>会给我一种绿色色调。 截图 使用 AppCompat 的可绘制对象按预期进行着色 着色不适用于从 AppCompat 复制的可绘制对象 在新的支持库v22.1之后,您可以使用类似这样的东西: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_home, menu); Drawable drawable = menu.findItem(R.id.action_clear).getIcon(); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, ContextCompat.getColor(this,R.color.textColorPrimary)); menu.findItem(R.id.action_clear).setIcon(drawable); return true; } app:iconTint 属性在支持库中的 SupportMenuInflater 中实现(至少在 28.0.0 中)。 已使用 API 15 及更高版本成功测试。 菜单资源文件: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/menu_settings" android:icon="@drawable/ic_settings_white_24dp" app:iconTint="?attr/appIconColorEnabled" <!-- using app name space instead of android --> android:menuCategory="system" android:orderInCategory="1" android:title="@string/menu_settings" app:showAsAction="never" /> <item android:id="@+id/menu_themes" android:icon="@drawable/ic_palette_white_24dp" app:iconTint="?attr/appIconColorEnabled" android:menuCategory="system" android:orderInCategory="2" android:title="@string/menu_themes" app:showAsAction="never" /> <item android:id="@+id/action_help" android:icon="@drawable/ic_help_white_24dp" app:iconTint="?attr/appIconColorEnabled" android:menuCategory="system" android:orderInCategory="3" android:title="@string/menu_help" app:showAsAction="never" /> </menu> (在本例中,?attr/appIconColorEnabled是应用程序主题中的自定义颜色属性,图标资源是矢量绘图。) 在 ColorFilter 上设置 MenuItem(色调)很简单。这是一个例子: Drawable drawable = menuItem.getIcon(); if (drawable != null) { // If we don't mutate the drawable, then all drawable's with this id will have a color // filter applied to it. drawable.mutate(); drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); drawable.setAlpha(alpha); } 如果您想支持不同的主题并且不想仅仅为了颜色或透明度而有额外的副本,上面的代码非常有帮助。 单击此处获取帮助程序类,以在菜单中的所有可绘制对象上设置ColorFilter,包括溢出图标。 在 onCreateOptionsMenu(Menu menu) 中,只需在扩充菜单后致电 MenuColorizer.colorMenu(this, menu, color); 即可;瞧;你的图标有颜色。 因为如果你看一下AppCompat中TintManager的源代码,你会看到: /** * Drawables which should be tinted with the value of {@code R.attr.colorControlNormal}, * using the default mode. */ private static final int[] TINT_COLOR_CONTROL_NORMAL = { R.drawable.abc_ic_ab_back_mtrl_am_alpha, R.drawable.abc_ic_go_search_api_mtrl_alpha, R.drawable.abc_ic_search_api_mtrl_alpha, R.drawable.abc_ic_commit_search_api_mtrl_alpha, R.drawable.abc_ic_clear_mtrl_alpha, R.drawable.abc_ic_menu_share_mtrl_alpha, R.drawable.abc_ic_menu_copy_mtrl_am_alpha, R.drawable.abc_ic_menu_cut_mtrl_alpha, R.drawable.abc_ic_menu_selectall_mtrl_alpha, R.drawable.abc_ic_menu_paste_mtrl_am_alpha, R.drawable.abc_ic_menu_moreoverflow_mtrl_alpha, R.drawable.abc_ic_voice_search_api_mtrl_alpha, R.drawable.abc_textfield_search_default_mtrl_alpha, R.drawable.abc_textfield_default_mtrl_alpha }; /** * Drawables which should be tinted with the value of {@code R.attr.colorControlActivated}, * using the default mode. */ private static final int[] TINT_COLOR_CONTROL_ACTIVATED = { R.drawable.abc_textfield_activated_mtrl_alpha, R.drawable.abc_textfield_search_activated_mtrl_alpha, R.drawable.abc_cab_background_top_mtrl_alpha }; /** * Drawables which should be tinted with the value of {@code android.R.attr.colorBackground}, * using the {@link android.graphics.PorterDuff.Mode#MULTIPLY} mode. */ private static final int[] TINT_COLOR_BACKGROUND_MULTIPLY = { R.drawable.abc_popup_background_mtrl_mult, R.drawable.abc_cab_background_internal_bg, R.drawable.abc_menu_hardkey_panel_mtrl_mult }; /** * Drawables which should be tinted using a state list containing values of * {@code R.attr.colorControlNormal} and {@code R.attr.colorControlActivated} */ private static final int[] TINT_COLOR_CONTROL_STATE_LIST = { R.drawable.abc_edit_text_material, R.drawable.abc_tab_indicator_material, R.drawable.abc_textfield_search_material, R.drawable.abc_spinner_mtrl_am_alpha, R.drawable.abc_btn_check_material, R.drawable.abc_btn_radio_material }; /** * Drawables which contain other drawables which should be tinted. The child drawable IDs * should be defined in one of the arrays above. */ private static final int[] CONTAINERS_WITH_TINT_CHILDREN = { R.drawable.abc_cab_background_top_material }; 这几乎意味着他们将特定的资源ID列入白名单以进行着色。 但我想你总能看到他们如何对这些图像进行着色并做同样的事情。就像在可绘制对象上设置 ColorFilter 一样简单。 我个人更喜欢这个方法link 使用以下内容创建 XML 布局: <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/ic_action_something" android:tint="@color/color_action_icons_tint"/> 并从菜单中引用此绘图: <item android:id="@+id/option_menu_item_something" android:icon="@drawable/ic_action_something_tined" 本线程中的大多数解决方案要么使用更新的 API,要么使用反射,或者使用密集视图查找来获取膨胀的 MenuItem。 但是,有一种更优雅的方法可以做到这一点。您需要一个自定义工具栏,因为您的“应用自定义色调”用例与公共样式/主题 API 不能很好地配合。 public class MyToolbar extends Toolbar { ... some constructors, extracting mAccentColor from AttrSet, etc @Override public void inflateMenu(@MenuRes int resId) { super.inflateMenu(resId); Menu menu = getMenu(); for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); Drawable icon = item.getIcon(); if (icon != null) { item.setIcon(applyTint(icon)); } } } void applyTint(Drawable icon){ icon.setColorFilter( new PorterDuffColorFilter(mAccentColor, PorterDuff.Mode.SRC_IN) ); } } 只需确保调用您的 Activity/Fragment 代码即可: toolbar.inflateMenu(R.menu.some_menu); toolbar.setOnMenuItemClickListener(someListener); 没有反射,没有视图查找,也没有那么多代码,是吧? 现在你可以忽略荒谬的onCreateOptionsMenu/onOptionsItemSelected。 这是我使用的解决方案;您可以在 onPrepareOptionsMenu() 或等效位置之后调用它。 mutate() 的原因是如果您碰巧在多个位置使用图标;如果没有变异,它们都会呈现相同的色调。 public class MenuTintUtils { public static void tintAllIcons(Menu menu, final int color) { for (int i = 0; i < menu.size(); ++i) { final MenuItem item = menu.getItem(i); tintMenuItemIcon(color, item); tintShareIconIfPresent(color, item); } } private static void tintMenuItemIcon(int color, MenuItem item) { final Drawable drawable = item.getIcon(); if (drawable != null) { final Drawable wrapped = DrawableCompat.wrap(drawable); drawable.mutate(); DrawableCompat.setTint(wrapped, color); item.setIcon(drawable); } } private static void tintShareIconIfPresent(int color, MenuItem item) { if (item.getActionView() != null) { final View actionView = item.getActionView(); final View expandActivitiesButton = actionView.findViewById(R.id.expand_activities_button); if (expandActivitiesButton != null) { final ImageView image = (ImageView) expandActivitiesButton.findViewById(R.id.image); if (image != null) { final Drawable drawable = image.getDrawable(); final Drawable wrapped = DrawableCompat.wrap(drawable); drawable.mutate(); DrawableCompat.setTint(wrapped, color); image.setImageDrawable(drawable); } } } } } 这不会解决溢出问题,但为此,你可以这样做: 布局: <android.support.v7.widget.Toolbar ... android:theme="@style/myToolbarTheme" /> 款式: <style name="myToolbarTheme"> <item name="colorControlNormal">#FF0000</item> </style> 这适用于 appcompat v23.1.0。 这对我有用: override fun onCreateOptionsMenu(menu: Menu?): Boolean { val inflater = menuInflater inflater.inflate(R.menu.player_menu, menu) //tinting menu item: val typedArray = theme.obtainStyledAttributes(IntArray(1) { android.R.attr.textColorSecondary }) val textColor = typedArray.getColor(0, 0) typedArray.recycle() val item = menu?.findItem(R.id.action_chapters) val icon = item?.icon icon?.setColorFilter(textColor, PorterDuff.Mode.SRC_IN); item?.icon = icon return true } 或者你可以在drawable xml中使用tint: <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:tint="?android:textColorSecondary" android:viewportWidth="384" android:viewportHeight="384"> <path android:fillColor="#FF000000" android:pathData="M0,277.333h384v42.667h-384z" /> <path android:fillColor="#FF000000" android:pathData="M0,170.667h384v42.667h-384z" /> <path android:fillColor="#FF000000" android:pathData="M0,64h384v42.667h-384z" /> </vector> @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_home, menu); //One item tint menu.get(itemId).getIcon().setTint(Color); //or all for(int i=0;i<menu.size();i++){ menu.get(i).getIcon().setTint(Color); } return true; } 我发现当我使用 android:iconTint 属性时,菜单项的颜色应用在设计预览中,但没有应用在应用程序中。但是,使用 app:iconTint 应用应用程序中的颜色,而不是设计预览中的颜色。

回答 10 投票 0

如何在底部按钮顶部显示小吃栏

我有一个带有数据绑定和协调器布局的布局,其中包含底部的按钮,该按钮在向下滚动时隐藏。我想在这个屏幕上显示 Snackbar,但是如果我显示它,它会显示 abo...

回答 1 投票 0

如何从flutter应用程序中删除Request_install_package权限?

我想发布我用 flutter 编写的 Android 应用程序。 Play 管理中心拒绝了我的请求。问题是 request_install_package 权限。所以我想删除它,但在发布报告中我看到了......

回答 1 投票 0

无法运行程序,因为模拟器中的加载设备未在 Android Studio 上运行

我刚刚下载了 Android Studio,因为我有一个学校作业。我接到的任务是创建一个应用程序。我已经下载了模拟器,而且操作系统至少是 5.0 (Lollipop)。当我...

回答 2 投票 0

如何从以前的版本中删除REQUEST_INSTALL_PACKAGES

在我的应用程序的早期版本中,我使用了 open_file ,不幸的是它使用了 REQUEST_INSTALL_PACKAGES 权限。 现在我删除了这个权限并更改了包,现在我使用 open_filex。 添加了这个co...

回答 4 投票 0

如何用flutter的dart语言动态改变app图标?

经过大量的研发,我能够使用flutter的dart语言动态更改应用程序图标。 为了达到这个目的: 起初我在寻找插件并找到了一个(flutter_dynamic_icon)...

回答 1 投票 0

如何查找给定 gradle 库的 gradle 插件 id?

我目前正在更新我的项目,作为步骤之一,我正在更改 gradle 文件以使用插件 { id 'xxx' } 方式,而不是旧的应用插件 'xxx' 方法。我能够迁移到...

回答 3 投票 0

从下到上逐渐填充一个圆圈android

我使用 xml 创建了一个带有笔划和白色背景的圆圈。如何根据用户操作(例如连续按下按钮)从下到上逐渐填充? 有免费的图书馆吗

回答 1 投票 0

Koin 类似于 Dagger IntoSet

Koin 是否提供将多个依赖项绑定到集合中的功能,就像 Dagger 的多重绑定那样? 假设我有这个界面: 接口初始化器:(应用程序...

回答 1 投票 0

Termux - npm 错误!错误:EPERM:不允许操作,符号链接

每当我安装 npm 包(例如:Puppeteer、Nightmare、Playwright)时,我都会收到相同的错误消息; 但是当我安装几乎所有的 npm-packages(axios、http、axios 等)时,它并没有显示出来......

回答 5 投票 0

Android 模拟器卡在启动时

在android studio中,模拟器(主要是我在android 11(R)上使用pixel 4)只是卡在启动时。当我检查日志时,我发现它由于这个错误而终止。遇到这个问题...

回答 1 投票 0

Android Studio 在最小化窗口或构建/运行项目时关闭我的项目

如标题所示。我被迫双击我的项目的“应用程序”模块,然后关闭“项目结构”菜单,以便浏览我的项目,每一个

回答 1 投票 0

在 google play 控制台哪里可以找到 assetlinks.json 的密钥库 sha256?

我熟悉的文件夹中有 assetlinks.json 文件。在哪里可以找到 sha256_cert_fingerprints? [ { “关系”: [ “delegate_permission/common.handle_all_urls” ], “目标”: { ...

回答 3 投票 0

如何以编程方式从Android获取whatsapp联系人?

我必须尝试从手机获取 WhatsApp 联系人,我得到了 WhatsApp 联系人的总数,但从 RawContacts 如何获取我不知道的 WhatsApp 号码和姓名。我试图找到一个所以...

回答 1 投票 0

隐藏开发者选项的命令

三星 Galaxy s7 edge 7.0,(已root) 我正在寻找一个 adb 命令来隐藏开发人员选项(即完全删除开发人员选项)。我已经审查了涉及该问题的所有帖子(

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.