How to open Activity as a dialog with ActionBar

后端 未结 3 848
独厮守ぢ
独厮守ぢ 2020-12-14 13:49

I want to open activity as dialog

public class MoveActivity extends Activity {
    private ListView list;
    private DocAdapter adapter;
    private ArrayLi         


        
3条回答
  •  甜味超标
    2020-12-14 14:12

    For using action bar in Dialog, you have to create a custom theme in your style.xml with parent as "Theme.AppCompat.Light".

    
    

    And add this style in your manifest with activity tag:

    
    

    and last add this code in your activity before setConytentView(layoutID);

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            this.requestWindowFeature(Window.FEATURE_ACTION_BAR);
            this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
                WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            LayoutParams params = this.getWindow().getAttributes(); 
            params.alpha = 1.0f;
            params.dimAmount = 0.5f;
            this.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); 
    
            // This sets the window size, while working around the IllegalStateException thrown by ActionBarView
            this.getWindow().setLayout(600,900);
    
            setContentView(R.layout.dialog_move);
    }
    

提交回复
热议问题