android - AppCompat Material Style 部件色调错误

标签 android android-appcompat

我正在使用 appcompat_v7 库。

在文档中说:

[...] AppCompat 在早期版本的 Android 上为一部分 UI 小部件提供了类似的行为:

AppCompat 工具栏提供的一切(操作模式等)

  • 编辑文本
  • 微调器
  • 复选框
  • 单选按钮
  • 切换(使用新的 android.support.v7.widget.SwitchCompat)
  • CheckedTextView 您不需要做任何特别的事情来使这些工作正常,只需像往常一样在您的布局中使用这些控件,AppCompat 将完成剩下的工作(有一些注意事项;请参阅下面的常见问题解答)。

这是我的代码:

值/styles.xml

<style name="AppBaseTheme" parent="Theme.AppCompat">
    <item name="colorPrimary">@color/material_blue_grey_800</item>
    <item name="colorPrimaryDark">@color/material_blue_grey_950</item>
    <item name="colorAccent">@color/material_deep_teal_200</item>
</style>

layout/activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.lollipoptest.MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="28dp"
    android:text="CheckBox" />

<RadioButton
    android:id="@+id/radioButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/checkBox1"
    android:layout_centerHorizontal="true"
    android:text="RadioButton" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/radioButton1"
    android:layout_centerHorizontal="true"
    android:ems="10" >

    <requestFocus />
</EditText>

默认的MainActivity.java没有变化

操作栏显示新的 Material 样式。编辑文本也是如此。 但复选框和单选按钮不是。 我做错了什么?

照片: https://drive.google.com/file/d/0B1jx6rK5CDqTRnhYVDU3V21JRlk/view?usp=sharing

最佳答案

我找到了一个解决方案:

 <CheckBox
        android:id="@+id/chbDevuelto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="16dp"
        android:button="@drawable/abc_btn_check_material"
        android:buttonTint="@color/colorAccent"
        android:layout_marginStart="16dp"
        android:focusable="false" />

这一行可以解决问题:

android:button="@drawable/abc_btn_check_material" android:buttonTint="@color/colorAccent"

适用于所有版本 :3

关于android - AppCompat Material Style 部件色调错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26595662/

相关文章:

android - 在 AOSP 中将文件添加到 userdata.img 的正确方法是什么?

android - 添加媒体路由器转换按钮时出错

android - ActionBarDrawer切换动画

android - 什么必须进入 'onPause()'(释放资源)

android - 迁移项目以gradle构建系统错误

android - 当 ActionMode 打开时,AppCompat 工具栏保持可见

android - 使用drawable vectors SDK < 21 : Binary XML file line #68: Error inflating class <unknown> invalid drawable tag vector

android - Appcompat v7 未纳入项目

android - 重置Android textview maxlines

android - 我该如何修复我的空指针异常