所以我想让这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前进 –