对话框中消失的操作栏 Activity

Disappearing action Bar in a Dialog Activity

我正在使用 activity 作为对话框。但是,对话框 activity 上的 actionBar 并没有消失。我试过使用:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_dialog);

}

没用。我还将应用程序的主题(来自清单)设置如下:

<activity
        android:name=".DialogActivity"
        android:label="@string/title_activity_dialog"
        android:theme="@style/Theme.AppCompat.Light.Dialog.Alert" >
    </activity>

以下是我得到的屏幕截图,我的目标是删除隐藏文本的无意义的白条。 The Screen Shot of the Emulator

谢谢。

创建自定义主题,例如。 styles.xml

中的自定义主题
<style name="CustomTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
</style>

并在 manifest.xml 中使用

    android:theme="@style/CustomTheme"

试试这个:

 <style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="windowNoTitle">true</item>

虽然理论上自定义没有标题栏的主题应该可行,但在我的情况下它不起作用。所以我通过从活动中删除以下部分来解决它_class.xml

        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>