Android 屏幕旋转监听
public class MainActivity extends Activity { App tool; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tool=new App(MainActivity.this); Button dialogButton=(Button)findViewById(R.id.dialog); dialogButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { tool.showDialog(); } }); Button changeButton=(Button)findViewById(R.id.changeButton); changeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Configuration configuration=getResources().getConfiguration(); if(configuration.orientation==Configuration.ORIENTATION_LANDSCAPE) MainActivity.this.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); else MainActivity.this.setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } }); } @Override public void onConfigurationChanged(Configuration newConfig){ super.onConfigurationChanged(newConfig); String string=newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE ? "Landscape":"Portrait"; tool.di(string); Toast.makeText(MainActivity.this,string,Toast.LENGTH_SHORT).show(); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。