中心浮动窗口/活动?

时间:2015-07-14 18:33:25

标签: java android android-activity

我正在使用AppCompat主题,并尝试将活动作为浮动活动启动。但是,如果设备的导航栏可见,它就不在窗口的中心。

屏幕截图:

enter image description here

从截图中可以看出,它认为导航栏是显示区域的一部分。

Style:
<style name="Theme.FloatingWindow.Popup.ClosableOnTouch" parent="Theme.AppCompat.Light.NoActionBar" >
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowCloseOnTouchOutside">true</item>
</style>

设置显示

public void setupDisplay(){
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
            WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.alpha = 1.0f;    // lower than one makes it more transparent
    params.dimAmount = 0.75f;  // set it higher if you want to dim behind the window
    getWindow().setAttributes(params);
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    getWindow().setLayout((int) (width * .9), (int) (height * .7));
}

有没有办法集中浮动活动?使用旧的Holo主题可以毫无障碍地工作,但我需要在我的应用程序中使用AppCompat主题

1 个答案:

答案 0 :(得分:0)

尝试在getWindow()之前设置params.height.setAttributes(params)