Android应用程序全屏

时间:2015-03-19 19:49:17

标签: android eclipse

我试图通过将以下代码添加到以下代码中指示的部分来全屏打开我的应用程序:

 requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

为了全屏打开我的应用程序,我尝试在下面的代码中的onCreate方法中插入上面的代码,但是当我运行应用程序时,我得到了应用程序意外停止的错误。

package com.example.expandinglists;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;





//import android.R;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity {
HashMap<String, List<String>> Movies_category;
List<String> Movies_List;
ExpandableListView Exp_list;
MoviesAdapter adapter;

private final String TAG = "DemoButton";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

   **//inputting code here**

    setContentView(R.layout.activity_main);
    Exp_list = (ExpandableListView) findViewById(R.id.exp_list);
    Movies_category = DataProvider.getInfo();
    Movies_List = new ArrayList<String>(Movies_category.keySet());
    adapter = new MoviesAdapter(this, Movies_category, Movies_List);
    Exp_list.setAdapter(adapter);




    //Button functionality: From Here
    setupMessageButton();
    //Button Functionality: Till Here
}


private void setupMessageButton() {
    // Button Functionality
    //1. Get Reference to the button
    Button messageButton = (Button) findViewById(R.id.btnDisplayMessage);



    //2. Button on Click Listener to run the button related code
    //View.OnClickListener myListener = new View.OnClickListener(){
    messageButton.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){
            //Log.i(TAG, "You Clicked the Button");
            Toast.makeText(MainActivity.this,"You Clicked it",Toast.LENGTH_LONG).show();

            startActivity(new Intent(MainActivity.this, SecondActivity.class));
        }           
    });
    //Use the button class create above
    //messageButton.setOnClickListener(myListener);

}


@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

更新

不确定它是否有帮助,但下面是来自logcat的日志。

2 个答案:

答案 0 :(得分:0)

按顺序编写以下代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Remove TitleBar
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);
    // Remove notification bar.
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

答案 1 :(得分:0)

我终于解决了我的问题。我将我的应用程序扩展到活动而不是 ActivityActionBar

public class MainActivity extends Activity {
...
}

感谢您的帮助,

Ĵ