Android 设备上的材质设计工具栏pre lollipop
我将学习下一个教程:Android 设备上的材质设计工具栏pre lollipop,android,tablet,android-5.0-lollipop,Android,Tablet,Android 5.0 Lollipop,我将学习下一个教程: 我想做类似的设计: 我知道我需要使用两个工具栏 values/themes.xml <resources> <style name="Theme.MiThema" parent="Theme.AppCompat.Light"> <!-- Here we setting appcompat’s actionBarStyle --> <!--<item name="actionBarStyle">@s
<resources>
<style name="Theme.MiThema" parent="Theme.AppCompat.Light">
<!-- Here we setting appcompat’s actionBarStyle -->
<!--<item name="actionBarStyle">@style/MyActionBarStyle</item>-->
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">@color/accent</item>
</style>
</resources>
布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal">
<!-- The toolbar -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- drawer view -->
<LinearLayout
android:layout_width="304dp"
android:layout_height="match_parent"
android:layout_gravity="left|start">
<!-- drawer content -->
</LinearLayout>
<!-- normal content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The rest of content view -->
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
代码在“setSupportActionBar(工具栏);”上报告一个错误:
(第一个问题)有什么问题吗?(已解决)
(第二个问题)
在我的布局上出现
“?attr/actionBarSize”和“?attr/colorPrimary”
我必须在哪里声明这些属性?
(第三个问题)
当我这样做时,两个工具栏只出现一次,我希望其中一个在另一个里面显示内容
我必须同时显示两个工具栏吗?
谢谢我可以回答你的第一个问题。它非常简单-您只需阅读IDE提供的消息。您使用了错误的工具栏。您试图传递给setSupportActionBar方法的工具栏来自程序包android.widget。但是,您必须使用程序包android.support.v7.widget中的工具栏。因此,您的导入是错误的-更正它们,您的代码应该可以工作。我可以为您的第一个问题提供答案。它非常简单-您只需阅读IDE提供的消息。您使用了错误的工具栏。您试图传递给setSupportActionBar方法的工具栏来自程序包android.widget。但是,您必须使用程序包android.support.v7.widget中的工具栏。因此,您的导入是错误的-更正它们,您的代码应该可以工作。我可以为您的第一个问题提供答案。它非常简单-您只需阅读IDE提供的消息。您使用了错误的工具栏。您试图传递给setSupportActionBar方法的工具栏来自程序包android.widget。但是,您必须使用程序包android.support.v7.widget中的工具栏。因此,您的导入是错误的-更正它们,您的代码应该可以工作。我可以为您的第一个问题提供答案。它非常简单-您只需阅读IDE提供的消息。您使用了错误的工具栏。您试图传递给setSupportActionBar方法的工具栏来自程序包android.widget。但是,您必须使用程序包android.support.v7.widget中的工具栏。所以你的导入是错误的-更正它们,你的代码应该可以工作。第一个问题解决后,让我试试第二个问题 首先,您不必在任何地方定义这些值,它们是预定义的
actionBarSize
。点击此链接:(其他SO Q上给出的答案)。
同样是现在,通过材料设计,谷歌分享了在材料设计中设计新应用程序(或升级旧应用程序)时使用的一些标准。您可以在此处遵循这些规范:工具栏中使用自定义背景色,只需添加一个合适的调色板,android:background=“@color/colorPrimary”
并在color.xml
中定义colorPrimary
值。使用此网站可以获得不同的颜色值:(我更喜欢此网站)
第一个问题解决后,让我试试第二个问题 首先,您不必在任何地方定义这些值,它们是预定义的
actionBarSize
。点击此链接:(其他SO Q上给出的答案)。
同样是现在,通过材料设计,谷歌分享了在材料设计中设计新应用程序(或升级旧应用程序)时使用的一些标准。您可以在此处遵循这些规范:工具栏中使用自定义背景色,只需添加一个合适的调色板,android:background=“@color/colorPrimary”
并在color.xml
中定义colorPrimary
值。使用此网站可以获得不同的颜色值:(我更喜欢此网站)
第一个问题解决后,让我试试第二个问题 首先,您不必在任何地方定义这些值,它们是预定义的
actionBarSize
。点击此链接:(其他SO Q上给出的答案)。
同样是现在,通过材料设计,谷歌分享了在材料设计中设计新应用程序(或升级旧应用程序)时使用的一些标准。您可以在此处遵循这些规范:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal">
<!-- The toolbar -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- drawer view -->
<LinearLayout
android:layout_width="304dp"
android:layout_height="match_parent"
android:layout_gravity="left|start">
<!-- drawer content -->
</LinearLayout>
<!-- normal content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The rest of content view -->
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>