package com.example.get_displaymetrics;
import android.os.Bundle; import android.app.Activity; import android.view.Menu;
/////////////////////////////////////// import android.util.DisplayMetrics; import android.view.Window; import android.view.WindowManager; import android.widget.TextView; /////////////////////////////////////// public class MainActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ///////////////////////////////////////// requestWindowFeature(Window.FEATURE_NO_TITLE); //全螢幕設定 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); ///////////////////////////////////////// setContentView(R.layout.activity_main); ///////////////////////////////////////// DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
TextView TextView1 = (TextView)findViewById(R.id.TextView01); TextView1.setText("手機銀幕大小為 "+metrics.widthPixels+" X "+metrics.heightPixels); ///////////////////////////////////////// }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }
}
|
沒有留言:
張貼留言