- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试从当前主题属性中给我的按钮颜色:android.R.attr.colorPrimary
或 R.attr.colorPrimary
应该返回黄色,但一直给我一种蓝色!我还在 list 中设置了主题。
例如,使用 android:background="?attr/colorPrimary"
设置工具栏的背景颜色会给出正确的颜色,但如果它是从代码设置的则不会。
这就是我尝试设置按钮颜色的方式:
TypedValue typedValue = new TypedValue();
App.getAppContex().getTheme().resolveAttribute(android.R.attr.colorPrimary, typedValue, true);
buttonColor = typedValue.data;
addButton.setText("SAVE");
addButton.getBackground().setColorFilter(buttonColor, PorterDuff.Mode.MULTIPLY);
这是我的“黄色”主题
<style name="AppTheme_Yellow" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primaryYellow</item>
<item name="colorPrimaryDark">@color/primary_darkYellow</item>
<item name="colorAccent">@color/accentYellow</item>
<item name="android:textColorPrimary">@color/primary_textYellow</item>
<item name="android:textColorSecondary">@color/secondary_textYellow</item>
<item name="android:icon">@color/iconsYellow</item>
<item name="actionOverflowButtonStyle">@style/OverFlowStyle</item>
<item name="popupMenuStyle">@style/popupMenuStyle</item>
“黄色”主题背后的颜色:
<color name="primaryYellow">#FFC107</color>
<color name="primary_darkYellow">#FFA000</color>
<color name="primary_lightYellow">#FFECB3</color>
<color name="accentYellow">#607D8B</color>
<color name="primary_textYellow">#212121</color>
<color name="secondary_textYellow">#727272</color>
<color name="iconsYellow">#212121</color>
<color name="dividerYellow">#B6B6B6</color>
最佳答案
我在我使用的全局应用程序上下文中发现了问题。App.getAppContex().getTheme().resolveAttribute(android.R.attr.colorPrimary, typedValue, true);
因此必须使用 getActivity() 或 UI Wigdets 在其中初始化的 Activity 的上下文:
getActivity().getTheme().resolveAttribute(android.R.attr.colorPrimary, typedValue, true);
关于android.R.attr.colorPrimary 总是给我错误的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37498842/
我找不到任何关于两者之间差异的信息: android:textColor="?attr/colorPrimary" 对比 android:textColor="?colorPrimary" 我读到“?
有人可以告诉我有什么区别吗 ?android:attr/colorPrimary 和 ?attr/colorPrimary 无论我使用哪个,结果都是一样的。尽管第一个选项导致android.view.
例如:在 values-v21/styles.xml 中 @color/primaryColor ` 它有效,而在 values/styles.xml 中,它必须是这样的: @c
我可以防止状态栏的颜色变成colorPrimary吗?我的意思是,我不想更改状态栏颜色,并保持原样(系统默认)。我在谷歌上搜索过这个,答案是隐藏状态栏。但我不想隐藏它。 我也不想将原色更改为状态栏的默
这是我的 colors.xml 文件。 #00ccff #00ccff #00ccff #212121 #000000 #FFFFFF #
根据 https://developer.android.com/training/material/theme.html , colorPrimary 应该设置操作栏颜色。 这在我的 mainAct
我正在学习使用工具栏小部件。 在按照 developer.android.com 上的指南进行操作时,我找到了这个 android:background="?attr/colorPrimary" 当我
根据谷歌文档,我应该可以在主题中使用 colorPrimary 设置工具栏背景的颜色,但它不起作用。这是我拥有的: 样式.xml: @color
我的问题很奇怪(我认为)。 使用 AppCompat 我对 ?attr/colorPrimary 的引用不起作用。 颜色.xml: @color/primary_material_dark
我正在尝试使工具栏背景色透明,但似乎显示的是 colorPrimary 主题。当我将工具栏的背景设置为标准颜色时,它会覆盖 colorPrimary 并按预期工作,但是有没有办法让我完全摆脱它以使工具
我正在使用 Theme.MaterialComponent ,但它不影响我的actionBar,为什么? 样式.xml @color/colorPrimary
(注意:这与 When using ActionMode, the status bar turns black on Lollipop 有点相关,所以可能有一些额外的信息被我不小心从这个问题中遗漏了
我有一个包含 2 个主题的 Android 应用。并且用户能够从应用程序其他地方的设置 Activity 切换主题。默认主题是 AppThemeBlue,应用启动时一切正常。但是,在用户将主题从设置
我正在尝试以编程方式更改 colorPrimary 和 colorAccent,但我找不到任何与它们相关的方法,例如 setThemeColorPrimary(int color) 。我找到的唯一方法
我只想以编程方式设置 contentScrim。所以我尝试了 int color = ContextCompat.getColor(getActivity(), R.attr.colorPrimary
我需要将应用程序栏上的颜色更改为某种渐变色。我在 drawable 文件夹中创建了 action_bar_bg.xml 文件: 我尝试更改 styles.xml 中的 colorPri
我很难在 Xamarin Studio 中编译我的 Android 应用程序。出现的错误如下: No resource found that matches the given name attr "
我正在尝试从当前主题属性中给我的按钮颜色:android.R.attr.colorPrimary 或 R.attr.colorPrimary 应该返回黄色,但一直给我一种蓝色!我还在 list 中设置
是否有可能以编程方式覆盖 colorPrimary、colorPrimaryDark 和 colorAccent 值,并在运行时从 java 代码相应地进行更改?如果可能请帮忙。 最佳答案 不,这不可
使用新的 Lollipop v21 API,我尝试使用 setStatusBarBackgroundColor 设置半透明状态栏的背景颜色,但使用 R.attr.colorPrimary 会导致颜色错
我是一名优秀的程序员,十分优秀!