Custom Dialog without title and border

后端 未结 8 878
终归单人心
终归单人心 2021-02-01 20:19

Based on the code here, http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog . I am successfully able to create a custom dialog with background and buttons ins

相关标签:
8条回答
  • 2021-02-01 20:46

    Try the following style in your styles.xml:

    <style name="free_floating_dialog" parent="@android:style/Theme.Holo.Light.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowCloseOnTouchOutside">false</item>
    </style>
    

    For more options see "Theme.Holo.Light.Dialog" which is part of the Android sources (since Honeycomb), or any other dialog style you based your's on.

    Then simply use this style as basis to your own dialog:

    Dialog myDialog = new Dialog(getActivity(), R.style.free_floating_dialog);
    myDialog.setContentView(R.layout.myContent);
    
    0 讨论(0)
  • 2021-02-01 20:50
    Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    
    0 讨论(0)
  • 2021-02-01 21:01
    Dialog dialog = new Dialog(Main.this);
    dialog.getWindow();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    
    0 讨论(0)
  • 2021-02-01 21:04

    I think this will help you out

    gameOver would be the dialog name and in setContentView it would be ur custom dialog layout

    gameOver = new Dialog(Main.this);
    gameOver.requestWindowFeature(Window.FEATURE_NO_TITLE);
    gameOver.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    gameOver.setCancelable(false);
    gameOver.setContentView(R.layout.gameover);
    
    0 讨论(0)
  • 2021-02-01 21:06

    I use this code and it work fine:

    AlertDialog.Builder builder = new AlertDialog.Builder(contextActivity,android.R.style.Theme_Holo_Dialog_NoActionBar);
    AlertDialog alertDialog = builder.create();
    alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    alertDialog.setView(myLayout,0,0,0,0);
    alertDialog.show();
    
    0 讨论(0)
  • 2021-02-01 21:06

    A Dialog cannot be created without a title. Further down in that tutorial it mentions:

    A dialog made with the base Dialog class must have a title. If you don't call setTitle(), then the space used for the title remains empty, but still visible. If you don't want a title at all, then you should create your custom dialog using the AlertDialog class. However, because an AlertDialog is created easiest with the AlertDialog.Builder class, you do not have access to the setContentView(int) method used above. Instead, you must use setView(View). This method accepts a View object, so you need to inflate the layout's root View object from XML.

    This answer solves both the title and the border problem using a custom style.

    0 讨论(0)
提交回复
热议问题