我最近尝试采用基于样式的方法来开发我的安卓应用。然而,我遇到了一个困境。
在我的布局文件中,我最初是这样写的:
<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>
在我的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>
我已经尝试了不同的变体,例如:
?android:buttonBarButtonStyle
?attr:buttonBarButtonStyle
@android:attr/buttonBarButtonStyle
@android:buttonBarButtonStyle
我还尝试过:
<item name="style">?android:attr/buttonBarButtonStyle</item>
无济于事。
我的应用程序因为找不到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" />