1

Im new on android development and I want to know how can I make an android activity fullscreen via a Icon placed on toolbar.

Thank You.

Please click on link for example image: Click to preview example

user3664679
  • 19
  • 1
  • 4

1 Answers1

1

I think this previous post may give you what you are looking for:

Fullscreen Activity in Android?

From post mentioned above:

You can do it programatically:

public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // remove title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
}
}

Or you can do it via your AndroidManifest.xml file:

<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

How your code should differ:

public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // remove title
    Button x = findViewById(R.id.yourButton);
       x.setOnClickListener(new View.OnClickListener() {
          @Override public void onClick(View v) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
             WindowManager.LayoutParams.FLAG_FULLSCREEN);
             setContentView(R.layout.main);
          }
       });
}
}

This would link your button with this code.

Community
  • 1
  • 1
Alexander N.
  • 1,458
  • 14
  • 25
  • 1
    it is posible with this code but not in onCreate...if he put new private void onFullScreenPressed () { .....this code.... }, otherwise it will be fullscreen at start without pressing button – Milos Lulic Jun 01 '16 at 19:38
  • If you think an answer to another question solves this issue as well then consider flagging the post as a duplicate rather than reposting the answer here. – ChrisF Jun 02 '16 at 12:38
  • I tried your method Alexander N. but its not working. My app crash when I click button from menu bar. – user3664679 Jun 02 '16 at 16:56
  • @user3664679 - What does your code look like for the onClickListener of your menu bar button? Can you post the error message from logcat? – Alexander N. Jun 02 '16 at 17:51
  • Button x = (Button) findViewById(R.id.fullscreen); assert x != null; x.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { supportRequestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_informatica); } }); and error is – user3664679 Jun 02 '16 at 18:07
  • @user3664679 - Since it is coming from a toolbar, you would want to wire it for the actionbar. See this link: http://stackoverflow.com/questions/22526498/android-actionbar-item-onclick – Alexander N. Jun 02 '16 at 18:08
  • So it sould be something like this: public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } if (id == R.id.fullscreen) { // startActivity(new Intent(this, ContactUS.class)); supportRequestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } } – user3664679 Jun 02 '16 at 18:14
  • Something like this: `@Override public boolean onOptionsItemSelected(MenuItem item){ switch(item.getItemId()){ case R.id.fullscreen: requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); return true; default: return super.onOptionsItemSelected(item); } }` – Alexander N. Jun 02 '16 at 18:16
  • Now i got this error: android.util.AndroidRuntimeException: Window feature must be requested before adding content – user3664679 Jun 02 '16 at 18:52