How do I create a transparent Activity on Android?

前端 未结 22 2138
忘掉有多难
忘掉有多难 2020-11-21 04:43

I want to create a transparent Activity on top of another activity.

How can I achieve this?

22条回答
  •  再見小時候
    2020-11-21 05:42

    Along with the gnobal's above solution, I had to set alpha to 0 in the layout file of that particular activity, because on certain phone (Redmi Narzo 20 pro running on Android 10) a dialog portion of the screen was showing with the screen that was supposed to be transparent. For some reason the windowIsFloating was causing this issue, but on removing it I wasn't getting the desired output.

    Steps:

    1. Add the following in the style.xml located under res > values > styles.xml

       
      

    2. Set the theme of the activity with the above style in AndroidManifest.xml

      
      

    3. Open your layout file of the activity on which you applied the above style and set it's alpha value to 0 (android:alpha="0") for the parent layout element.

      
      
      
        
      
      
      

    Please Note: You'll have to extend you activity using Activity() class and not AppCompatActivity for using the above solution.

提交回复
热议问题