Android how to set Activity full screen

Three ways to set all activities to full screen:

1. Set in code

   If you use this method, you need to set each activity one by one, which will be very troublesome. I am used to extracting a base class BaseActivity for the activity, and after setting it in this base class, let all the activities inherit. This base class, which is also a common pattern in development.

public class BaseActivity extends Activity {  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate (savedInstanceState);  
        // Set the activity to full screen  
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                             WindowManager.LayoutParams.FLAG_FULLSCREEN);  
    }  
}

 

2. Configure in the AndroidManifest.xml file

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  

 

3. Create a custom styles.xml under the directory res/values

<!-- Customize Fullscreen Theme-->  
<style name="Theme.CustomizedFullScreen" parent="android:Theme">  
    <item name="android:windowNoTitle">true</item>  
    <item name="android:windowFullscreen">true</item>  
</style>  

 Configure in the AndroidManifest.xml file

android:theme="@style/Theme.CustomizedFullScreen"  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326026275&siteId=291194637