How can I create my own theme for alertDialog?

后端 未结 5 845
有刺的猬
有刺的猬 2021-01-16 13:21

I want to create a different theme for all of alertDialog instances. I need my own title view instead of the usual black title background. All text should have a blue color,

5条回答
  •  一向
    一向 (楼主)
    2021-01-16 14:10

    You can use layout as Different themes, styles, Backgrounds

    customdialog.xml

    
    
    
        
    
            
    
                
    
                
            
    
            
    
                
    
    
                
    
                  

    customDialog.java

    final Dialog favDialog = new Dialog(Myclass.this,
                android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
    
    
    favDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        favDialog.getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
        favDialog.setContentView(R.layout.reloadurlpopuplayout);
    
        favDialog.setCancelable(false);
    
        ImageView dialogImage = (ImageView) favDialog
                .findViewById(R.id.dialogheaderimage1);
    
        dialogImage.setBackgroundResource(R.drawable.questionmark);
    
        TextView dialogMesage = (TextView ) favDialog
                .findViewById(R.id.dialogmessgetext1);
        TextView dialogHeader = (TextView) favDialog
                .findViewById(R.id.dialogheadertext1);
    
        String descText = getString(R.string.RetryReportMessage);
    
    
        dialogMesage.setBackgroundColor(0x00000000);
    
        dialogMesage.setText(descText);
    
        dialogHeader.setText(R.string.BrockenLinkHeader);
    
        try {
            favDialog.show();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    

提交回复
热议问题