如何继承Android样式属性?

Cha*_*had 6 java android styles

我最近尝试采用基于样式的方式接近我的Android应用程序.但是,我陷入了这种困境.

在我的布局文件中,我最初有这个:

 <LinearLayout
         android:id="@+id/layout_event_buttons"
         style="?android:attr/buttonBarStyle"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
         android:orientation="horizontal" >

         <ImageButton
             android:id="@+id/btn_create_event"
             style="?android:attr/buttonBarButtonStyle"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:contentDescription="@string/btn_save"
             android:src="@drawable/content_save"
             android:text="@string/btn_save" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在我的styles.xml中,我尝试这样做没有运气:

<style name="Buttons" parent="?android:attr/buttonBarButtonStyle">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我已经尝试了以上不同的变体,如:

?android:buttonBarButtonStyle

?attr:buttonBarButtonStyle

@android:attr/buttonBarButtonStyle

@android:buttonBarButtonStyle

我也尝试过:

<item name="style">?android:attr/buttonBarButtonStyle</item> 
Run Code Online (Sandbox Code Playgroud)

无济于事.

我的应用程序将无法编译,因为它无法找到buttonBarButtonStyle资源.

这就是我应用它的方式.如果我只是继承Holo等常见主题,我的其他风格也可以正常工作.

<ImageButton
     style="@style/Buttons"
     android:id="@+id/btn_create_event"
     android:contentDescription="@string/btn_save"
     android:src="@drawable/content_save"
     android:text="@string/btn_save" />
Run Code Online (Sandbox Code Playgroud)

Cha*_*had 5

发现答案类似于这篇文章: android:attr 样式如何工作?

原来这种风格是私人的,你可能需要完全复制它才能实现它。:(