Mimicking Material-design raised button style, trouble with Stackoverflow solution

只谈情不闲聊 提交于 2019-12-12 05:17:33

问题


I'm struggling with the top answer here: How to mimic the Material-design raised button style, even for pre-Lollipop (minus the special effects)?

I made a mock program with the bare essentials listed by @spierce7

  • In gradle: compile "com.android.support:appcompat-v7:24.1.1" // (24.2.1 in my case)
  • In styles.xml: <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  • In Android Manifest: android:theme="@style/AppTheme"
  • My Activity extends AppCompatActivity
  • My button is an AppCompatButton (or a plain Button, doesn't matter)

Here is the layout 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>

The result is this:

The corner floating button inflates with the "raised look", but not my AppCompatButton.

And I'm still not seeing raised buttons in pre-Lollipop. What am I missing or doing wrong?


回答1:


After checking again on the latest version it seems that the appcompat library isn't backporting the raised button effect for me either. I've updated my answer accordingly.

My recommendation is that you just use what the appcompat library provides for you, as it's still matching the material design guidelines. If for some reason you MUST have an exact backport (an exact backport would include not only the raised button effect, but also the raised pressed animation effect, along with the ripple), you'll need to look to some 3rd party libraries. I've seen 3rd party libraries with partial backports, but no full backports, but I haven't looked thoroughly.

If you wish to make your own, you'll need to follow my old answer to the question you posted, extending CardView.



来源:https://stackoverflow.com/questions/40108069/mimicking-material-design-raised-button-style-trouble-with-stackoverflow-soluti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!