Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 不带立面的AppCompat按钮_Android_Android Button_Android Appcompat_Android Elevation - Fatal编程技术网

Android 不带立面的AppCompat按钮

Android 不带立面的AppCompat按钮,android,android-button,android-appcompat,android-elevation,Android,Android Button,Android Appcompat,Android Elevation,我的应用程序中有几十个按钮,并且有一种继承自Widget.AppCompat.Button的风格。大多数按钮都有高程和状态更改动画。太棒了 不可怕的是,一些按钮没有任何额外的优点 下面是一个工作按钮的示例 <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin

我的应用程序中有几十个按钮,并且有一种继承自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

我想问题出在你的活动主题上

值得一提的是,按钮的风格来自活动主题。 你能做的是:

  • 定义样式:

    <style name="ThemeMaterialButtonColor" parent="Base.Widget.AppCompat.Button">
    <item name="colorButtonNormal">@color/md_teal_500</item></style>
    
    
    @颜色/md_teal_500
    
  • 然后在xml中的按钮中添加以下内容:

    应用程序:theme=“@style/ThemeMaterialButtonColor”


  • 我想问题出在你的活动主题上

    值得一提的是,按钮的风格来自活动主题。 你能做的是:

  • 定义样式:

    <style name="ThemeMaterialButtonColor" parent="Base.Widget.AppCompat.Button">
    <item name="colorButtonNormal">@color/md_teal_500</item></style>
    
    
    @颜色/md_teal_500
    
  • 然后在xml中的按钮中添加以下内容:

    应用程序:theme=“@style/ThemeMaterialButtonColor”


  • 您是否尝试在每个按钮上显式地添加样式?@Androider遗憾的是没有骰子:/我尝试删除minHeight属性,并将代码放入活动的主布局中,效果很好。这些参数可能有问题。您是否尝试在每个按钮上显式添加样式?@Androider遗憾的是没有骰子:/我尝试删除minHeight属性并将代码放入活动的主布局中,效果很好。这些参数可能有问题。