Android @style 资源未解析

标签 android android-studio

我正在使用 Android Studio 开发 Android 应用程序。 我在 ..../src/main/res/values 中有一个样式资源 -

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

我在 Styles.xml 文件中定义了几个样式,工作室抛出错误,指出样式无法在它解析的位置解析,并应用于同一 Activity 代码和同一 styles.xml 文件中的一个 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"
            />

android studio 显示的错误-

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) 

最佳答案

只需将 android:layout_widthandroid:layout_height 移动到您的按钮。 Android 并不总是从样式中读取此字段。这取决于Android需要什么参数来定位元素。

我认为this answer可能更有帮助。

关于Android @style 资源未解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18177241/

相关文章:

android - 在 Android 上更改 ListView 项目的背景颜色

java - 安卓 : Error:Execution failed for task ':transformClassesWithJarMergingForDebug'

android-studio - 插件错误 : Plugin * is compatible with IntelliJ IDEA only because it doesn't define any explicit module dependencies

android - Android Studio如何导入Gradle项目

java - 如何使用 ArrayList 中的按钮

android - 单击按钮一次打开文件夹(SD 卡)中的所有图像

java - Android http 连接被拒绝

Android waitForMonitorWithTimeout 方法不起作用

android - 如何返回到导航图的根?

Android adb log - 在应用程序崩溃后收集最近的日志