Reputation: 11
I am trying to create a transparent overlay, should work on top of other application window also using code below.
Problems are:
1) it doesn't work at the top of other application window.
2) background color is not transparent.
java code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//-----
final WindowManager.LayoutParams window_params=getWindow().getAttributes();
// window_params.screenBrightness=1f;
window_params.format = PixelFormat.TRANSPARENT;
window_params.type=2006;
getWindow().setAttributes(window_params);
//------
view = new MyView(this); //MyView view = new MyView(this);
view.setBackgroundColor(Color.TRANSPARENT);
view.changeSomethingInWindow(); // keep an eye on this method
setContentView(R.layout.main); //setContentView(view); //setContentView(view ,new LayoutParams(200,400));
}
public class MyView extends View{
public MyView(Context context) {
super(context);
}
public void changeSomethingInWindow(){
// get a reference of the activity
Activity parent = (Activity)getContext();
Window window = parent.getWindow();
window.getWindowManager();
window.setLayout(300, 400); //window.setLayout(getHeight()/2, getWidth()/2);
window.setFormat(PixelFormat.TRANSPARENT);
//window = new Window(this, R.style.Theme_Transparent);
// window.setBackgroundDrawableResource(getWindowVisibility());
window.setFlags(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY);
window.getWindowStyle();
window.getDecorView();
}
}
style.xml:
<?xml version="1.0" encoding="utf-8"?> <resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
manifest.xml:android:theme="@style/Theme.Transparent"
i have used this in manifest.xml
try to help me, to figure out the solution of this problem. Thanks.
Upvotes: 1
Views: 3940
Reputation: 972
Try something like that:
private static final int FLAGS = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
WindowManager.LayoutParams params = new WindowManager.LayoutParams(0, FLAGS, PixelFormat.TRANSLUCENT);
getWindowManager().addView (overlayView, params);
Remove FLAG_NOT_TOUCHABLE if you want receive touches. Pay attention to "addView" parameters.
Upvotes: 1