模仿材料 - 设计提升按钮样式,Stackoverflow解决方案出现问题

时间:2016-10-18 12:18:41

标签: android material-design android-button

我在这里努力争取最佳答案:How to mimic the Material-design raised button style, even for pre-Lollipop (minus the special effects)?

我使用@spierce7

列出的基本要素制作了一个模拟程序
  • 在gradle中:compile "com.android.support:appcompat-v7:24.1.1" //(在我的情况下为24.2.1)
  • 在styles.xml中:<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  • 在Android Manifest中:android:theme="@style/AppTheme"
  • 我的活动扩展了AppCompatActivity
  • 我的按钮是AppCompatButton(或普通Button,无关紧要)

这是布局XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main">

    <android.support.v7.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:id="@+id/textview_helloworld"/>

    <android.support.v7.widget.AppCompatButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_below="@id/textview_helloworld"/>
</RelativeLayout>

结果如下:

enter image description here

角落浮动按钮充满了&#34;凸起的外观&#34;,但不是我的AppCompatButton。

我还没有在前棒棒糖中看到凸起的按钮。我错过了什么或做错了什么?

1 个答案:

答案 0 :(得分:0)

再次检查最新版本之后,似乎appcompat库也没有向我推送凸起的按钮效果。我已相应更新了我的答案。

我的建议是,您只需使用appcompat库为您提供的内容,因为它仍然符合材料设计指南。如果由于某种原因你必须有一个精确的backport(一个确切的backport不仅包括凸起的按钮效果,还包括凸起的按下动画效果,以及涟漪),你需要查看一些第三方库。我已经看到第三方图书馆有部分向后移动,但没有完整的后向移动,但我看不太彻底。

如果您想自己做,您需要按照我对您发布的问题的旧回答,延长CardView