首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >居中浮动窗口/活动?

居中浮动窗口/活动?
EN

Stack Overflow用户
提问于 2015-07-15 02:33:25
回答 1查看 556关注 0票数 1

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

截图:

正如您从屏幕截图中看到的,它认为导航栏是显示区域的一部分。

代码语言:javascript
运行
复制
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>

设置显示

代码语言:javascript
运行
复制
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));
}

有没有办法将浮动活动放在中心位置?使用旧的全息主题没有问题,但我需要在我的应用程序中使用AppCompat主题

EN

回答 1

Stack Overflow用户

发布于 2015-12-03 22:09:42

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31414595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档