【问题标题】:How to incorporate Material Design in App when using android studio?使用android studio时如何在App中加入Material Design?
【发布时间】:2015-09-19 15:41:16
【问题描述】:

我正在学习 android 应用程序开发和使用 android studio。我想获得材料设计的感觉和外观。我正在关注 android 开发者网站并遇到 android:Theme.Material 主题,但它说它在 API 级别 21 之前的 API 中不受支持! https://developer.android.com/training/material/compatibility.html

我用谷歌搜索过,但如果没有适当的材料设计支持库,我仍然有很多困惑,如果没有,我们如何才能为旧版本实现它?如果有人可以向我指出正确的链接/指南/教程,那将非常有帮助。

【问题讨论】:

    标签: android android-studio material-design


    【解决方案1】:

    材料设计的支持库

    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.android.support:support-v4:22.1.1'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'
    compile 'com.android.support:design:22.2.0'
    

    材料设计主题

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
    
    </style>
    

    【讨论】:

    • 感谢您提及这些库。那么,如果使用 Theme.AppCompat 作为父主题,是否已经在使用材质主题?
    • 是的,你可以在里面定义&lt;item name="colorPrimary"&gt;&lt;item name="colorAccent"&gt;。但是你需要添加一些库来使用材料设计组件
    • 你的应用程序中的Activities应该扩展AppCompatActivity,你应该在布局文件中定义一个工具栏。
    • 是的,我做到了。我正在使用工具栏以及其他使用库的材质小部件。如果您可以进一步指出一些链接/教程,那将很有帮助。否则我很高兴到现在为止。
    【解决方案2】:

    您可以使用 AppCompat v21(或更高版本)

    dependencies {
        compile 'com.android.support:appcompat-v7:23.0.0'
        ...
    }
    

    还有这个values/themes.xml:

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

    所以基本上你可以使用Theme.AppCompat.Light 和上述风格的主题。

    更多详情见:Android Developers Blog(这也是kris larson在他的回答中提到的)

    【讨论】:

      【解决方案3】:

      这是 Android 开发者博客上一篇关于 Material Design 支持库的精彩文章:

      Android Design Support Library | Android Developer's Blog

      【讨论】:

      • 谢谢!很好的教程。
      猜你喜欢
      • 2016-08-18
      • 2015-03-08
      • 2016-02-01
      • 2019-04-25
      • 1970-01-01
      • 2020-09-30
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多