我解决了许多堆栈溢出问题。我遇到了具体的问题,所以是时候第一次直接问你了。
我使用 ActionBarSherlock。我希望我的应用在任何设备上看起来都一样。我需要对话框,所以我决定使用 ABS 的对话框主题。因此,我为我的自定义对话框创建了一个活动,并将其设置为看起来像 Holo,即使在早期的 Android 版本上也是如此。
这就是它在 Android 2.3.3 模拟器上的样子:
https://dl.dropbox.com/u/49293039/problem2.jpg(对不起,由于缺乏我的声誉,我无法将其作为图片发布......)
我喜欢这个。但是当我想在 ICS 和 JB 设备/模拟器上测试它时,我看到了……
https://dl.dropbox.com/u/49293039/problem1.jpg
如您所见,我的按钮没有显示。让我快速浏览一下我的源代码:
@layout/my_dialog.xml,按钮栏实现的一部分:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_margin="0dp"
android:orientation="vertical"
android:padding="0dp">
<View
style="@style/HorizontalDivider"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:orientation="horizontal"
android:padding="0dp">
<Button
android:id="@+id/cancelButton"
android:text="@string/cancel_button"
style="@style/HoloBarButton"
/>
<View
style="@style/VerticalDivider"
/>
<Button
android:id="@+id/proceedButton"
android:text="@string/add_button"
style="@style/HoloBarButton"/>
</LinearLayout>
</LinearLayout>
@values/styles.xml
<style name="HorizontalDivider">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">?android:attr/listDivider</item>
<item name="android:layout_margin">0dp</item>
</style>
<style name="VerticalDivider">
<item name="android:layout_width">1dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">?android:attr/listDivider</item>
<item name="android:layout_margin">0dp</item>
</style>
<style name="HoloBarButton">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:layout_margin">0dp</item>
<item name="android:textColor">#ffffff</item>
<item name="android:layout_weight">50</item>
</style>
任何想法如何解决这个问题?实现两个两个版本的对话框(4.0+ 的原生对话框和旧 Android 版本的自定义对话框)会带来更多的工作量。是否有可能修复它或者仅仅是我的错?
我试图通过将 targetSdkVersion 从 15 更改为 8 和 10(最小值为 8)来解决它,但它没有帮助。如果有不清楚的地方,请询问。谢谢你的努力。