appcompat 22.1.0 中的 android:theme 是否仅适用于工具栏?
Does android:theme in appcompat 22.1.0 only work for Toolbar?
在下面的布局中
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
TextView
未在 L 之前的设备上使用主题文本颜色。如果我将此主题声明移动到 TextView,它适用于所有设备。 Chris Banes 在他的文章中写道:
In 22.1.0 we now have expanded that functionality so that you can set
a theme on any view in your layouts.
https://chris.banes.me/2015/04/22/support-libraries-v22-1-0/
所以我很困惑,虫子?
编辑:
我查看了工具栏,发现工具栏似乎也有这个问题——以下布局也没有按预期工作:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:layout_width="wrap_content"
android:text="#@#@SDAG"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
使用新版本 (v22.1) 的支持库,您的 activity 应该扩展 AppCompatActivity
而不是您之前扩展过的 ActionBarActivity
。
这是 Google 开发者的 post:http://android-developers.blogspot.com/2015/04/android-support-library-221.html
我找到了问题的根源。我直接将项目添加到 R.id.content。喜欢 LayoutInflater.from(this).inflate(R.layout.my_activity, findViewById(R.id.content);
而不是使用 setContentView
方法来完成所有神奇的事情。不幸的是,在文档中没有说明您必须使用 setContentXXX
方法。
在下面的布局中
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
TextView
未在 L 之前的设备上使用主题文本颜色。如果我将此主题声明移动到 TextView,它适用于所有设备。 Chris Banes 在他的文章中写道:
In 22.1.0 we now have expanded that functionality so that you can set a theme on any view in your layouts. https://chris.banes.me/2015/04/22/support-libraries-v22-1-0/
所以我很困惑,虫子?
编辑:
我查看了工具栏,发现工具栏似乎也有这个问题——以下布局也没有按预期工作:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:layout_width="wrap_content"
android:text="#@#@SDAG"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
使用新版本 (v22.1) 的支持库,您的 activity 应该扩展 AppCompatActivity
而不是您之前扩展过的 ActionBarActivity
。
这是 Google 开发者的 post:http://android-developers.blogspot.com/2015/04/android-support-library-221.html
我找到了问题的根源。我直接将项目添加到 R.id.content。喜欢 LayoutInflater.from(this).inflate(R.layout.my_activity, findViewById(R.id.content);
而不是使用 setContentView
方法来完成所有神奇的事情。不幸的是,在文档中没有说明您必须使用 setContentXXX
方法。