繁体   English   中英

没有高程的AppCompat按钮

[英]AppCompat Button Without Elevation

我的应用程序中有几十个按钮,还有从Widget.AppCompat.Button继承的Widget.AppCompat.Button 大多数按钮具有高程和状态更改动画。 真棒。

令人敬畏的是,其中一些按钮没有任何额外的优点。

这是一个工作按钮的示例

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="?attr/defaultPadding"
    android:minHeight="?attr/minTouchSize"
    android:textAppearance="?attr/textAppearanceListRowLabel" />

这是按钮不起作用的摘录

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_weight="1"
        android:minHeight="?attr/minTouchSize" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:minHeight="?attr/minTouchSize" />
</LinearLayout>

这些是在单独的布局上。 我尝试过的事情:

  • 我已将button1添加到与按钮栏相同的布局文件中,并且button1仍然有效。
  • 如果我从栏中的一个按钮上卸下砝码,它们将不起作用。
  • 我尝试将我的按钮样式明确地放在每个按钮上
  • 如果我将按钮栏设置为垂直布局并使按钮与父项匹配,那么它将起作用! 但这不是我想要的。

我想使这些按钮在水平布局时具有状态动画和高程。 我也希望按钮占据相等的空间,然后彼此相邻放置两个。 我该如何实现?

我正在使用appcompat 22.2.1

我想问题出在您的活动主题中!

值得一提的是,这些按钮采用了Activity THEME的样式。 您可以执行以下操作:

  1. 定义样式:

     <style name="ThemeMaterialButtonColor" parent="Base.Widget.AppCompat.Button"> <item name="colorButtonNormal">@color/md_teal_500</item></style> 
  2. 然后在您的xml按钮中添加以下代码:

    应用:主题= “@风格/ ThemeMaterialButtonColor”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM