所以我想讓這3行可以作爲我應用程序中每個活動的函數。 我試圖做一個簡單的MyMethods類與3線公共無效的,但我沒有工作(無法解析法)Android,全屏全局方法
package com.example.myapplication;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
//landscape,fullscreen,no action bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//I want those 3 lines above to be one void function
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendMessage(View view){
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.editText);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
我的意思是這樣的: Mymethods.fullscreen();全屏在Mymethods類中是靜態無效的,所以我可以在應用中的每個活動中使用這個函數 –
它的工作,謝謝。我會嘗試製作「全屏()」方法。 –
@PawełRubin前進 –