- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在我的项目中使用 CollapsingToolbarLayout
。
当 CollapsingToolbarLayout
展开时,默认情况下它是白色的(即在 style.xml< 中的
)。android:textColorSecondary
中定义
我的问题:
I want to change my menu item icon color.
xml文件:
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="200dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="false">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
主要 Activity 代码:
AppBarLayout appBarLayout = findViewById(R.id.appbar_layout);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean isShow;
int scrollRange = -1;
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (scrollRange == -1) {
scrollRange = appBarLayout.getTotalScrollRange();
}
if (scrollRange + verticalOffset == 0) {
//collapse map
//TODO: change share icon color - set white share icon
isShow = true;
} else if (isShow) {
//expanded map
//TODO: change share icon color - set dark share icon
isShow = false;
}
}
});
到目前为止我尝试了什么:
设置 toolbar.getNavigationIcon().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
但是它改变了后退按钮的颜色,而我想更改共享按钮图标颜色。
DrawableCompat.setTint
不适用于我的情况。
谢谢。
最佳答案
我会这样做:
private Drawable drawable;
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.your_menu, menu);
drawable = menu.getItem(0).getIcon(); // set 0 if you have only one item in menu
//this also will work
//drawable = menu.findItem(your item id).getIcon();
//
if(drawable != null) {
drawable.mutate();
}
return true;
}
现在在onOffsetChanged
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (scrollRange == -1) {
scrollRange = appBarLayout.getTotalScrollRange();
}
if (scrollRange + verticalOffset == 0) {
//collapse map
//TODO: change share icon color - set white share icon
isShow = true;
drawable.setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
} else if (isShow) {
//expanded map
//TODO: change share icon color - set dark share icon
isShow = false;
drawable.setColorFilter(getResources().getColor(R.color.shadow), PorterDuff.Mode.SRC_ATOP);
}
}
关于android - 折叠工具栏布局 : Change menu item icon color when it is expanded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47771799/
解释 onCreateOptionsMenu(Menu menu) 和 onPrepareOptionsMenu(Menu menu) 的区别。 最佳答案 onCreateOptionsMenu()
所以我又一次为一些问题而苦苦挣扎。这次是这样的,当我将鼠标悬停在 portfoilio 的下拉菜单上时(当网站处于移动 View 模式时),它只会越过其他元素,我尝试使所有内容相对,删除 float
我正在为移动设备设置新菜单。一切都设置好了,但在我点击任何菜单项后,它并没有关闭菜单和菜单覆盖。 有什么办法解决这个问题吗? 我在下面提供了我的 CSS 和 HTML 代码。 CSS margin
我正在使用 selenium webdriver 为单页 Web 应用程序开发一个 Java 框架,使用以下模式:PageObject、SlowLoadableComponent(责任链)、PageF
我是一个动态创建和选项菜单,选项菜单取决于 onCreate() 阶段创建的数据。 问题在于 onCreateOptionsMenu() 在创建数据之前被调用。有没有办法在onCreate()之后执行
HTML: Portfolio Services About Testimonials Request a Quote CSS: ul#menu li {
我是 extjs 的新手。我想在从 Ext.menu.Menu 选择菜单项时关联一个商店。我正在使用 extjs 4.1.0。我在网上搜索甚至通过 sencha doc 但我找不到任何方法来实现这一目
我正在使用 Bootstrap 3.0.0 制作网站 除了下拉菜单不起作用之外,一切都很好。 在文件的头部,我做出了以下声明: 有什么东西不见了? html 应该是正确的:
我刚刚开始学习 JQuery/JavaScript,我无法弄清楚使用 (".menu") 和 ("menu") 之间的区别以及应该在哪里使用它们? 最佳答案 它是menue,jquery使用css选择
我正在尝试向我的应用程序页面之一添加菜单,但由于某种原因,它没有出现。我使这个特定页面扩展了 AppCompactActivity 并覆盖了 onCreateOptionsMenu(Menu menu
我需要完全控制透视菜单。 我已经侵入平台以禁用上下文菜单: private void disablePerspectiveToolbarMenu() { PerspectiveBarManag
假设我有一个包含一些项目的菜单 (Ext.menu.Menu)。显示菜单时,用户 cat 右键单击它的项目,将显示浏览器上下文菜单(带有“将链接另存为...”等元素)。 如何禁用该浏览器上下文菜单
我有一个按钮,单击后将展开一个菜单项,我希望能够通过 java 脚本控制台以编程方式单击其中一个菜单项。这是我单击按钮所需的内容,但在单击 Ext.menu.Menu 时需要一些帮助 var fire
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等建议的问题。您可以编辑问题,以便可以用事实和引用来回答它。 5年前关
在这里,我正在从事 safari 扩展开发。我已经在 safari 浏览器上成功获得了开发者证书。 在这里,我可以在工具栏项上创建菜单和子菜单,但根据我的项目要求,我必须在栏中包含菜单和菜单项。 请建
我正在使用 Java 和 Android Studio。我需要更改操作栏上的图像。我需要做的是根据从远程传感器接收到的读数来更改在操作栏上显示的图像。因此,我无法使用可点击的方法,而是使用一些代码在从
亲爱的..我有一个问题。在 Firebug 展上: $("#menu ul.menu").lavaLamp 不是 menu.js 中的函数 悬停在菜单上不显示。我把这个问题显示出来:
因此,我接到了一项任务,即使用 CSS 为网页创建一个汉堡包式多级菜单。这里的问题是添加一个子菜单,使其成为一个多层次的汉堡包。下面是我到目前为止为汉堡包多级菜单编写的代码片段 body { marg
我正在学习 Android 并遵循简单的相机应用教程。我复制了一段代码,但出现错误,我不确定原因。 我使用的教程是, http://iwearshorts.com/blog/android-devel
我的/About 中有一个包含路线的子菜单。 这个子菜单称为 AboutMenu 并出现在/About 下的所有页面,例如 =>/About/Company 和/About/Info。 练习示例显示
我是一名优秀的程序员,十分优秀!