Android风格:与x27的区别;风格=“@android:style/XYZ“';和';style=";?android:attr/XYZ“';?

Android风格:与x27的区别;风格=“@android:style/XYZ“';和';style=";?android:attr/XYZ“';?,android,android-layout,android-resources,android-styles,Android,Android Layout,Android Resources,Android Styles,我正在尝试将按钮的样式设置为我在中询问的样式 我成功了,为感兴趣的人提供了以下xml: <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="bottom" android:divider="@android:drawable/divider_horizonta

我正在尝试将按钮的样式设置为我在中询问的样式

我成功了,为感兴趣的人提供了以下xml:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:divider="@android:drawable/divider_horizontal_dark"
        android:gravity="bottom"
        android:orientation="vertical"
        android:paddingTop="16dip"
        android:showDividers="beginning|end" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:measureWithLargestChild="true"
            android:orientation="horizontal"
            android:divider="@android:drawable/divider_horizontal_dark"
            android:showDividers="middle" >                             


            <Button
                android:id="@+id/cancel_button"
                style="?android:attr/buttonBarButtonStyle"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_weight="1"
                android:maxLines="2"
                android:text="@string/cancel_button" />

            <Button
                android:id="@+id/login_button"
                style="?android:attr/buttonBarButtonStyle"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="1"
                android:filterTouchesWhenObscured="true"
                android:maxLines="2"
                android:text="@string/login_button" />

        </LinearLayout>
    </LinearLayout>

不过有一个问题。eclipse内容助手不知道以下资源解析发生了什么:

style=“?android:attr/buttonBarButtonStyle”

我熟悉典型的分辨率(eclipse的content assist知道这一点)

style=@android/style/…

…但我不清楚两者之间的区别。似乎有些样式属性出现在其中一个中,但在另一个中却没有。例如,以下内容不能解决任何问题:

style=@android:attr/buttonBarStyle

这也不是:

style=“@android:style/buttonBarStyle

我猜这里有两个问题:

  • 为什么资源引用语法不同
  • 为什么在attr类别下会出现令人困惑的风格分类错误
  • attr类别的用途是什么
  • 谢谢!

    从现在开始(此处转述):

    在ID前面使用问号意味着您希望访问在样式主题中定义的样式属性,而不是硬编码属性

    可以将其视为取消对主题属性的引用以获取它所指向的资源,而不是引用属性本身


    ?android:attr/buttonBarButtonStyle或只是?android:buttonBarButtonStyle(attr是可选的)

    @android:style/Widget.Button
    
    这将在内部取消对@android:style/Widget.Button的引用,该按钮在appcompat/res/values/themes.xml文件中定义

    (?android:)-始终链接到当前应用主题的属性值。因此,我们只能引用android定义的样式,而不是创建新样式并提供硬编码的值

    谷歌文档说,

    <item name="buttonBarButtonStyle">@android:style/Widget.Button</item>