Remove title bar and status bar from Activity, and switch between Bitmap and drawable

Keywords: Android

1, Set in code

public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
//Remove title   
requestWindowFeature(Window.FEATURE_NO_TITLE);   
//Remove the status bar above the Activity
getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , WindowManager.LayoutParams. FLAG_FULLSCREEN);  
   setContentView(R.layout.main); 
}

//perhaps
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.main);

2, Modify in configuration file

(key code Android:theme = "@ android:style/Theme.NoTitleBar.Fullscreen". If you want to just remove the title bar, you don't need to add fullscreen. In addition, if you want to remove the title bar and status bar from the whole application, you need to add this code to the application tab. If you just want an activity to work, you need to add this code to the corresponding activity

To hide a title block, you need to use a predefined style:
android:theme="@android:style/Theme.NoTitleBar".

Hide the status bar: android:theme = "@ android:style/Theme.NoTitleBar.Fullscreen"
I would also like to explain here that after running our application with the former, we will see a short status bar and then the full screen, while the second method will not.

Mutual conversion of Bitmap and drawable:

1. Create a new Bitmap based on the existing Drawable:

private Bitmap bitmap;  
 private void drawableToBitamp(Drawable drawable)  
     {  
         int w = drawable.getIntrinsicWidth();  
         int h = drawable.getIntrinsicHeight();  
         System.out.println("Drawable turn Bitmap");  
         Bitmap.Config config =   
                 drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888  
                         : Bitmap.Config.RGB_565;  
         bitmap = Bitmap.createBitmap(w,h,config);  
         //Note that the following three lines of code need to be used. No canvas in View or surface View.drawBitmapI can't see the picture  
         Canvas canvas = new Canvas(bitmap);     
         drawable.setBounds(0, 0, w, h);     
         drawable.draw(canvas);}

2. Take Bitmap directly from the existing Drawable:

private Bitmap bitmap;  

 private void drawableToBitamp(Drawable drawable)  
   {  
        BitmapDrawable bd = (BitmapDrawable) drawable;  
         bitmap = bd.getBitmap();  
     }

Posted by lanas on Tue, 07 Apr 2020 09:56:53 -0700