gpt4 book ai didi

android - 从 ActionBar 迁移到 ToolBar

转载 作者:太空狗 更新时间:2023-10-29 15:52:34 26 4
gpt4 key购买 nike

我需要升级应用程序以使用 Material Design。我要做的第一件事是显示新的 Toolbar,但我不确定应该如何执行此操作。

我有我的主要 FragmentActivity,我膨胀了一些 menu 并执行:

getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.main_color)));

我也使用NavigationDrawer,所以我也为抽屉设置了一个图标。

也就是说,我如何使用新的 Toolbar 实现相同的行为?

最佳答案

看看android developers blog .它包含“如何”的解释

不久

工具栏 View 一样添加到您的 Activity 布局

<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" />

你应该将你的Toolbar设置为ActionBar

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);

不要忘记样式。将新的 style.xml 添加到资源目录 values-21v,之后您的工具栏 将由您的colorPrimary 着色>

<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>

关于android - 从 ActionBar 迁移到 ToolBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28332865/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com