Activity should be transparent, but has a black background

My use case is recording the activity of an overlay controller to preview a landscape camera. I followed the instructions from several tutorials to write a transparent topic.

So my res / values ​​/style.xml look like this:

<resources> <style name="Theme" parent="android:Theme" /> <style name="Theme.Transparent"> <item name="android:windowBackground">@drawable/transparent_background</item> </style> <drawable name="transparent_background">#00000000</drawable> </resources> 

Action snippet:

  <activity android:name=".CameraPreview" android:label="Camera" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Controlls" android:label="Controlls" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent"> </activity> 

When I start this activity from my root activity, the layout is drawn correctly, but the background remains black. I tried using @android:style/Theme.Translucent instead, but this theme inherits orientation from the calling activity (landscape), and that is not what I want.

Edit:

An application containing a camera preview is set to landscape mode, as it does not display the preview correctly in portrait orientation. (see old google bug report )

What I wanted to do was set up independent activity for the user interaction interface in front of the camera surface mount (for this action you need to install a "portrait" or even better a "sensor")

+6
android android-layout
source share
4 answers

Try the built-in @android:style/Theme.Translucent instead of your custom, according to this blog post . I didn’t try to do this myself, so I don’t know if the equipment works there, working or not.

+2
source share

I found out that another important child element for describing the style above <item name="android:windowIsTranslucent">true</item> missing.

Problem:

This child also causes the orientation of the activity to synchronize with the caller. (same effect as @android:style/Theme.Translucent )

+1
source share

I ran into the same problem that you are describing (regarding the translucent background and screen orientation), but in the end I agreed that this is exactly how it works. In fact, it actually makes sense that it works that way. I can’t think of any screen-based system that supports mixing portrait and landscape views, so why Android?

I assume that the general rule is that all visible actions should have the same orientation, regardless of the attributes in the manifest file. If all are set to "sensor" , then all of them will change, if they are attached to a portrait or landscape, then the rest should follow (and whoever does this last “wins”).

I think the developers were so obvious that they did not have to document it :)

+1
source share

Delete and everything done

 @Override public void onAttachedToWindow() {} 
0
source share

All Articles