Vya*_*sky 5 android themes styles dialog android-actionbar
我希望我的一个活动看起来像一个对话框,并使用了一个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>
Run Code Online (Sandbox Code Playgroud)
我使用以下代码启动活动:
Intent intent = new Intent(this, DeviceListActivity.class);
startActivityForResult(intent, REQUEST_CONNECT_DEVICE);
Run Code Online (Sandbox Code Playgroud)
首先,当我遇到这个问题时,我尝试使用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>
Run Code Online (Sandbox Code Playgroud)
现在,在 中AndroidManifest.xml,添加android:theme="@style/MyCustomDialog"到您的活动中。
当然,MyCustomDialog可以重命名为任何你想要的。