Android, SeekBar in dialog

后端 未结 4 1911
自闭症患者
自闭症患者 2020-12-30 11:28

I would like to use a dialog with a seekbar in my application. But I don\'t really know how to do it because I lack experience with android.

So, when you press a but

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 11:58

    I hope this will help you. Try this Code...

    final AlertDialog.Builder alert = new AlertDialog.Builder(this); 
    
        alert.setTitle("Alert Box"); 
        alert.setMessage("Edit Text"); 
    
        LinearLayout linear=new LinearLayout(this); 
    
        linear.setOrientation(1); 
        TextView text=new TextView(this); 
        text.setText("Hello Android"); 
        text.setPadding(10, 10, 10, 10); 
    
        SeekBar seek=new SeekBar(this); 
    
        linear.addView(seek); 
        linear.addView(text); 
    
        alert.setView(linear); 
    
    
    
        alert.setPositiveButton("Ok",new DialogInterface.OnClickListener() 
        { 
            public void onClick(DialogInterface dialog,int id)  
            { 
                Toast.makeText(getApplicationContext(), "OK Pressed",Toast.LENGTH_LONG).show(); 
                finish(); 
            } 
        }); 
    
        alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener()  
        { 
            public void onClick(DialogInterface dialog,int id)  
            { 
                Toast.makeText(getApplicationContext(), "Cancel Pressed",Toast.LENGTH_LONG).show(); 
                finish(); 
            } 
        }); 
    
        alert.show(); 
    

提交回复
热议问题