我正在开发一个简单的应用来测试材料设计.我正在使用com.android.support:appcompat-v7:21.0.0,我的活动看起来像:
public class MyActivity extends ActionBarActivity {
...
}
Run Code Online (Sandbox Code Playgroud)
布局定义为:
<LinearLayout 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"
tools:context=".MyActivity">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="128dp"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimaryDark"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
现在我按照材料指南定义了我的主题:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary500</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark700</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我想在Android 5之前更改状态栏颜色并将其设置为colorPrimaryDark但我无法找到方法.我试过用:
getWindow().setStatusBarColor(..)
Run Code Online (Sandbox Code Playgroud)
但是,从第21级开始可以使用setStatusBar颜色.为什么如果我colorPrimaryDark在我的主题中定义并使用appcompact,状态栏不会改变颜色?有人可以帮忙吗?
我正在测试材料设计,我正在使用扩展工具栏开发应用程序.我的应用程序非常简单:主要活动扩展ActionBarActivity,我的布局如下:
<LinearLayout 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"
tools:context=".WeatherActivity"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_toolbar"
android:layout_height="128dp"
popupTheme="@style/ActionBarPopupThemeOverlay"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="@string/location_placeholder"
android:textAlignment="viewStart"
android:layout_gravity="start"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
现在我想将标题显示为当前位置.我注意到的第一件事是在我的Android模拟器(API 18)中,标题似乎不符合关于左边距底边距的材料指南,它出现在左侧并垂直输入工具栏内.我应该使用工具栏标题(toolbar.setTitle)还是其他什么?其次,如果我想创建更复杂的东西,如标题和简短的描述(如布局结构中的材料指南所示),我的布局应该是什么?谢谢您的支持!