Search code examples
androidandroid-layoutandroid-activityandroid-xml

Show debug banner on Android


I am trying to display the little debug banner in the top right of the app just like Flutter does but in Android.

enter image description here

What is the best way to implement this? I just want it on this activity.


Solution

  • How to draw behind the status bar?

    Make the app draw behind the status bar by setting the following flags in your theme.

     <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:statusBarColor">@color/transparent</item>
    </style>
    

    Use fitsSystemWindows property inside each activity layout xml to determine which content should go behind the statusbar and which content should go below the statusbar. So here in your case, the debug banner should go behind the translucent statusbar. Create the xml file for the activity like that way.

    How to rotate the view?

    Just use the rotate attribute as shown in the below sample snippet

    <View
    android:rotation="45"
    ... />
    

    How to determine whether it is debug build or release build?

    Use the BuildConfig.DEBUG flag