Images for AlertDialog buttons

后端 未结 6 1969
再見小時候
再見小時候 2021-01-11 14:19

Is it possible to add drawables to the positive, negative and neutral buttons of an AlertDialog? If yes, then how?

6条回答
  •  时光说笑
    2021-01-11 15:24

    1.first create a new layout file to store the imagebuttons:new_layout.xml;

    
    
    
        
        
    
        
        
    
       
        
    
    
    

    2.add the code below to where you want the dialogue to show:

        final AlertDialog alertDialog = new AlertDialog.Builder(TalkerActivity.this).create();
        alertDialog.show();
        Window win = alertDialog.getWindow();
        win.setContentView(R.layout.new_layout);
    
        //Game
        ImageButton game_btn = (ImageButton)win.findViewById(R.id.game);
        game_btn.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
    
            }
        });
    
        //Browser
        ImageButton browser_btn = (ImageButton)win.findViewById(R.id.browser);
        browser_btn.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
    
            }
        });
    
        //Email
        ImageButton email_btn = (ImageButton)win.findViewById(R.id.email);
        email_btn.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
    
            }
        });
    

    link:http://blog.csdn.net/willproud/article/details/9191971

提交回复
热议问题