AppCompatButton在Android Marshmallow上不显示

3

我在一个线性布局中放置了两个android.support.v7.widget.AppCompatButton。它们在Android 4.x和5.x版本中显示和工作正常,但在6.0版本上不会显示出来(手机是S7 Edge)。

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/btnAsk"
        android:textSize="16sp"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="@string/btn_ask"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="5dp"
        android:layout_marginBottom="5dp"
        android:textStyle="bold"
        android:background="@drawable/round_shape_btn"
        android:textColor="@color/white"/>

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/btnBuy"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:textSize="16sp"
        android:layout_height="wrap_content"
        android:text="@string/btn_buy"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="5dp"
        android:textStyle="bold"
        android:background="@drawable/round_shape_btn"
        android:textColor="@color/white" />
</LinearLayout>

我在谷歌上搜索并查看了SOF,但未找到可行的解决方案。需要大家的帮助!


这肯定是一个有趣的现象。你为什么需要使用AppCompatButton呢?普通按钮无法实现什么? - Vucko
@Vucko:这个库包括对Material Design用户界面实现的支持。https://developer.android.com/topic/libraries/support-library/features.html#v7-appcompat - erol yeniaras
3个回答

0

您可以在布局中直接使用Button而不必指定AppCompatButton,因为根据<docs>中AppCompatButton的说明:

当您在布局中使用Button时,将自动使用[AppCompatButton]。只有在编写自定义视图时才需要手动使用此类。


我会尝试并尽快给出反馈。谢谢回复! - erol yeniaras
@erolyeniaras 有什么进展吗? - Ed Holloway-George
我将它更改为Button,但问题并未解决。然后我切换回AppCompatButton,并将布局从LinearLayout更改为RelativeLayout,按钮出现了。感到困惑。我已向Google报告了此问题。 - erol yeniaras

0

我不知道具体是怎么发生的,但我将布局从

LinearLayout 更改为 RelativeLayout

然后按钮就出现了。很奇怪!


0

我认为你的问题在于LinearLayout的Orientation属性没有设置,默认是水平方向,这会导致视图不显示,特别是如果第一个视图的宽度设置为MATCH_PARENT。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接