我希望使自己的活动之一看起来像一个对话框,并为其使用了Theme.AppCompat.Dialog主题,但是这使它的操作栏看起来很糟糕(见下文)。
现在背景被切成标题字符串的长度,我找不到修复它的任何主题属性。
如何避免这种情况?
styles.xml的相关部分:
<style name="DeviceListTheme" parent="Theme.AppCompat.Dialog">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
我使用以下代码开始活动:
Intent intent = new Intent(this, DeviceListActivity.class);
startActivityForResult(intent, REQUEST_CONNECT_DEVICE);
首先,当我遇到此问题时,我尝试使用,supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
但这对我不起作用,并且没有效果。
删除对话框活动顶部的栏的另一种方法是创建自定义样式并将其应用于该活动。
在中styles.xml
,创建新样式,如下所示:
<style name="MyCustomDialog" parent="Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
现在,在中AndroidManifest.xml
,添加android:theme="@style/MyCustomDialog"
到您的活动中。
当然,MyCustomDialog
可以重命名为任何您想要的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句