简体   繁体   English

显示由活动创建的不带标题的对话框

[英]show dialog made from Activity without title

I am showing a dialog made from Activity. 我正在显示一个由“活动”创建的对话框。 The dialog activity has set no title in onCreate() callback: 对话框活动未在onCreate()回调中设置标题:

public class MyDialogActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // set window feature no title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.my_dialog);
    ...
  }
  ...
}

I defined a style for the activity: 我为活动定义了一种样式:

<style name="Theme.MyDialog" parent="@style/Theme.AppCompat.Light.Dialog">
     <item name="android:windowFrame">@null</item>
     <item name="android:windowIsFloating">true</item>
     <item name="android:windowContentOverlay">@null</item>
     <item name="android:windowIsTranslucent">true</item>
     <item name="android:windowNoTitle">true</item>
     <item name="android:windowActionBar">false</item>
     <item name="background">@android:color/transparent</item>
     <item name="android:windowBackground">@drawable/my_bg</item>
 </style>

And in AndroidManifest.xml: 在AndroidManifest.xml中:

<activity
       android:name=".MyDialogActivity"
       android:theme="@style/Theme.MyDialog">
</activity>

But when I show the dialog, there is always a title(which shows my app's name) on the dialog. 但是,当我显示对话框时,对话框上总是有一个标题(显示我的应用程序的名称)。

It is weird not only because it still shows title, but also shows my app's name as title, as you can see, I haven't set any title. 这很奇怪, 不仅因为它仍然显示标题, 而且还显示我应用程序的名称作为标题,如您所见,我没有设置任何标题。 It looks like an Android default behaviour, but...how to get rid of the title? 看起来像Android的默认行为,但是...如何摆脱标题?

(I am running on Android 5.1.1) (我在Android 5.1.1上运行)

You can try adding the following style to your Activity for imitating a dialog: 您可以尝试将以下样式添加到“活动”中以模仿对话框:

<style name="Theme.AppCompat.TranslucentDialog" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@color/colorTransparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>

where colorTransparent is the following: 其中colorTransparent是以下内容:

<color name="colorTransparent">#64000000</color>

Then use it with: 然后将其与:

<activity
     android:name=".MyDialogActivity"
     android:theme="@style/Theme.AppCompat.TranslucentDialog">
</activity>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM