【问题标题】:Custom Button style is appearing in preview but not on device API 27自定义按钮样式出现在预览中,但不在设备 API 27 上
【发布时间】:2018-11-19 13:57:17
【问题描述】:

我创建了一个自定义按钮,它出现在预览中,但没有出现在我的手机上。最低API是17,我手机的API是27。

//custom button
<style name="taskButton"  parent="Widget.AppCompat.Button">
    <item name="android:layout_alignParentStart">true</item>
    <item name="android:drawablePadding">-3dp</item>
    <item name="android:background">@color/Red</item>
    <item name="android:textAlignment">viewStart</item>
</style>

//xml 
 <Button
                android:id="@+id/homeButton"
                style="@style/taskButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center|start"
                android:drawableStart="@drawable/ic_home_black_24dp"
                android:text="Home"
                android:textAllCaps="false"
                android:visibility="visible" />

【问题讨论】:

  • 按钮没有出现或者样式设置不正确?
  • 按钮出现了,但样式不对
  • Button 的膨胀主题是什么?可能这只是您的 Activity 的主题,但如果 Button 标签的父标签具有 `android:theme: 属性(或者如果您的 LayoutInflater 明确设置了主题),它可能会有所不同。
  • 而且,我想,这个主题源自什么主题?我从这里查看的重要信息是您使用的是 AppCompat 主题、MaterialComponents 主题还是其他主题。

标签: android android-layout android-xml android-styles android-studio-3.2


【解决方案1】:

我想我发现了问题所在。 我有 2 个 xml 文件,一个用于 api 21+,另一个用于 api 21-。 我删除了这两个版本,并为所有版本重新创建了一个新版本。我的问题已经解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    • 2015-08-07
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 2015-10-30
    • 1970-01-01
    相关资源
    最近更新 更多