4

Android アプリの開発に Android Studio を使用しています。..../src/main/res/values 内にスタイル リソースがあります -

colors.xml
dimens.xml
strings.xml
styles.xml

Styles.xml ファイルにいくつかのスタイルが定義されていますが、同じアクティビティ コード内の同じ styles.xml ファイルからスタイルが解決され、1 つの LinearLayout に適用される場所で、スタイルを解決できないというエラーがスタジオからスローされます。動作する LinearLayout 内の Button に別のスタイルを適用しようとしています。

スタイルで -

<style name="LoginButton">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginTop">10dp</item>
        <item name="android:layout_marginLeft">25dp</item>
        <item name="android:layout_marginRight">25dp</item>
        <item name="android:background">@color/navy_blue</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:text">@string/action_sign_in</item>
        <item name="android:paddingLeft">50dp</item>
        <item name="android:paddingRight">50dp</item>
        <item name="android:layout_gravity">center</item>
</style>

そして activity_login.xml で -

<Button style="@style/LoginButton"
                    android:id="@+id/sign_in_button"
            />

エラーアンドロイドスタジオが示しています -

Rendering Problems NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts. <Button> does not set the required layout_width attribute:     Set to wrap_content, Set to match_parent <Button> does not set the required layout_height attribute:     Set to wrap_content, Set to match_parent  Or: Automatically add all missing attributes   Couldn't resolve resource @style/LoginButton (6 similar errors not shown) 
4

2 に答える 2

2

ボタンに移動するだけandroid:layout_widthです。android:layout_heightAndroid は常にスタイルからこのフィールドを読み取るわけではありません。要素を配置するためにAndroidが必要とするパラメータによって異なります。

この回答がより役立つと思います。

于 2013-08-11T23:01:37.323 に答える
-2

使用してandroid:styleください。style定義されていないものを使用しています。

編集:私の答えを無視してください。

于 2013-08-11T22:32:10.067 に答える