我怎么能编写我的布局代码,以便我的布局看起来对所有Android设备统一?

时间:2017-02-01 12:30:32

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

例如:以下代码我为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>

问题出现在我的设备(Coolpad Note3 Lite)上有android 6.0按钮没有得到TurquoiseColor的背景,我已经在主题中应用了。虽然它适用于其他设备。如何解决此问题。

1 个答案:

答案 0 :(得分:0)

您的按钮

<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%正常工作