Android 从ActionBar迁移到工具栏
我需要升级一个应用程序以使用Android 从ActionBar迁移到工具栏,android,compatibility,material-design,android-toolbar,Android,Compatibility,Material Design,Android Toolbar,我需要升级一个应用程序以使用材质设计。我要做的第一件事是显示新的工具栏,但我不确定该如何操作 我有我的主要碎片活动,我将一些菜单充气并执行以下操作: getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.main_color))); 我还使用了NavigationDrawer,因此我也为这个抽屉设置了一个图标 那么,我如何使用新的工具栏实现相同的行为呢?请看一看。它包含“如何
材质设计
。我要做的第一件事是显示新的工具栏
,但我不确定该如何操作
我有我的主要碎片活动
,我将一些菜单
充气并执行以下操作:
getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.main_color)));
我还使用了NavigationDrawer
,因此我也为这个抽屉设置了一个图标
那么,我如何使用新的工具栏实现相同的行为呢?请看一看。它包含“如何”的解释
很快
将类似于视图的工具栏添加到活动的布局中
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
别忘了造型。将new style.xml添加到resource dir values-21v,之后,工具栏将由您的colorPrimary着色
@颜色/我的颜色太棒了
@颜色/我的超棒的颜色
@颜色/口音
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- colorPrimary is used for the default action bar background -->
<item name=”colorPrimary”>@color/my_awesome_color</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name=”colorPrimaryDark”>@color/my_awesome_darker_color</item>
<!-- colorAccent is used as the default value for colorControlActivated,
which is used to tint widgets -->
<item name=”colorAccent”>@color/accent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight, and colorSwitchThumbNormal. -->
</style>