Make an android activity full screen over a button

浪子不回头ぞ 提交于 2019-12-11 14:24:55

问题


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


回答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.



来源:https://stackoverflow.com/questions/37577015/make-an-android-activity-full-screen-over-a-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!