- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在开始一个新项目,所以这个项目或多或少是“空的”。我刚刚添加了一个带有 MainActivityFragment 的 MainActivity。我根本没有向它们添加任何代码。
现在,我编辑 styles.xml,使其看起来像这样:
<resources>
<!-- Base application theme. -->
<style name="MyTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="android:windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<item name="android:colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="android:colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="android:colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
</style>
</resources>
因此,如您所见,我扩展了 Material 主题。
然后我创建一个工具栏 xml 文件 (mytoolbar.xml),如下所示:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abc_ic_voice_search_api_mtrl_alpha"/>
</android.support.v7.widget.Toolbar>
问题是:
我不知道为什么。我已经完成了 gradle 同步、清理、重建、重新启动 IDE (Android Studio 1.2.1.1),但没有任何效果。
有什么想法吗?
最佳答案
Android [pre-lollipop] 操作系统中存在一个错误,不允许您在 drawable 中使用 attr。这是错误的链接:
https://code.google.com/p/android/issues/detail?id=26251
Android 开发团队发布了一个修复程序,但它适用于 android L 及更高版本。有关此问题的解决方法,请参阅以下解决方案:
关于android - "Failed to convert ?attr/colorPrimary into a drawable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31512957/
我找不到任何关于两者之间差异的信息: 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 会导致颜色错
我是一名优秀的程序员,十分优秀!