【问题标题】:How could I write my code for layout such that my layout looks uniform for all android devices?我如何编写布局代码,使我的布局对于所有 android 设备看起来都是统一的?
【发布时间】:2017-06-18 04:57:37
【问题描述】:

例如:我为 Button 编写的以下代码:

 <Button
    android:id="@+id/button_submit"
    android:layout_width="match_parent"
    android:layout_height="58dp"
    android:layout_marginBottom="20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:theme="@style/AppTheme.Button"
    android:text="Done"
    android:textSize="20sp" />

并且应用于Button的主题代码是

<style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
    <item name="android:textAllCaps">false</item>
    <item name="colorButtonNormal">@color/appTurquoiseColor</item>
    <item name="android:textColor">@android:color/white</item>
</style>

问题出在我的具有 android 6.0 的设备(Coolpad Note3 Lite)上,按钮没有获得我在主题中应用的 TurquoiseColor 背景。虽然它在其他设备上运行良好。如何解决此问题。

【问题讨论】:

    标签: android xml user-interface layout android-6.0-marshmallow


    【解决方案1】:

    您的按钮

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/button_submit"
        style="@style/AppTheme.Button"
        android:layout_width="match_parent"
        android:layout_height="58dp"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:text="Done"
        android:textSize="20sp" />
    

    你的风格

    <style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
            <item name="android:textAllCaps">false</item>
            <item name="android:background">@color/appTurquoiseColor</item>
            <item name="android:textColor">@android:color/white</item>
        </style>
    

    100% 正常工作

    【讨论】:

    • @Nikhil 使用按钮的样式标签而不是 android:theme
    • 我尝试了两种方式:案例 I:style="AppTheme.Button" 案例 II:style="@style/AppTheme.Button" 但没有成功
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 2016-01-05
    • 1970-01-01
    • 2014-04-03
    相关资源
    最近更新 更多