Android type_system_overlay不覆盖整个屏幕

时间:2015-04-30 18:25:22

标签: android android-layout android-intent android-service

我已经在这个问题上敲了一个星期了。各种谷歌搜索显示了可能的解决方案,但没有任何效果。

我会发布一个链接到我的应用程序,但我相信这是不允许的。 简单的应用程序:按下按钮,它会激活半透明的彩色叠加层。

问题:

当激活叠加层时,如果导航栏是透明的,则它不会覆盖/移动到导航栏后面。

示例:您可以看到导航栏未被覆盖。透明的蓝色是叠加层。

example of issue.

在超级和设置内容视图后的主要活动中:

Intent i = new Intent(getApplicationContext(), TintOverlayService.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);

TintOverlayService.class

    LayoutInflater li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    mTopView = (LinearLayout) li.inflate(R.layout.red_overlay, null, false);
    mTopView.setBackgroundColor(Color.parseColor(colorCode.replace("#", tintValue)));

   WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
            PixelFormat.TRANSLUCENT);    

Color.parseColor(colorCode.replace("#", tintValue))只应用用户选择的颜色和不透明度级别。

red_overlay布局的XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#40370000"
    android:theme="@android:style/Theme.Holo.NoActionBar.TranslucentDecor"
    android:fitsSystemWindows="true"
    >
</LinearLayout>

我尝试了各种WindowManager.LayoutParams,布局,自定义主题,视图标记,沉浸式视图。我现在感到头疼。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我所要做的就是为参数添加两个标志:

WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;

booklistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        Intent intent = new Intent(getApplicationContext(), BookInfoActivity.class);


        editTextBooktitle = (TextView) view.findViewById(R.id.text_book_title);
        String book_title = editTextBooktitle.getText().toString();
        intent.putExtra(EXTRA_MSG1, book_title);

        editTextBookauthor = (TextView) view.findViewById(R.id.text_book_author);
        String bookauthor = editTextBookauthor.getText().toString();
        intent.putExtra(EXTRA_MSG2, bookauthor);

        editTextBookdate = (TextView) view.findViewById(R.id.text_book_date);
        String bookdate = editTextBookdate.getText().toString();
        intent.putExtra(EXTRA_MSG3, bookdate);

        editTextBookrating = (TextView) view.findViewById(R.id.text_book_rating);
        String bookrating = editTextBookrating.getText().toString();
        intent.putExtra(EXTRA_MSG4, bookrating);

        editTextBookshelf = (TextView) view.findViewById(R.id.text_book_shelf);
        String bookshelf = editTextBookshelf.getText().toString();
        intent.putExtra(EXTRA_MSG5, bookshelf);

        startActivity(intent);
    }
}
相关问题