StatusBar/Toolbar的隐藏显示,窗体背景设置

  直接上图,类似相册的效果。

   

  两张图都是隐藏了statusbar(状态栏),第一张显示toolbar,窗体背景为白色,第二张隐藏toolbar,窗体背景为黑色。(第一张的下面就是一个 layout_width="fill_parent" 的textview,点击是隐藏)

  首先,statusbar(状态栏)的隐藏,在这里直接在theme里面style加一条

<item name="android:windowFullscreen">true</item>

  或者android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”,

  或者在activity里加入一下代码

 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
         WindowManager.LayoutParams.FLAG_FULLSCREEN);

  接着,toolbar左边的返回箭头(Google官方不推荐使用)

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

  当屏幕被触摸,响应事件

@Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        if (event.getAction() == MotionEvent.ACTION_DOWN) {        //屏幕被触摸
            if (s == 1) {                             //隐藏toolbar和textview
                showToolbar.animate().translationY(-showToolbar.getHeight()).setInterpolator(new AccelerateInterpolator(2)); //属性动画
                FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) titleShower.getLayoutParams();
                int fabBottomMargin = lp.bottomMargin;
                titleShower.animate().translationY(titleShower.getHeight() + fabBottomMargin).setInterpolator(new AccelerateInterpolator(2)).start();
                shower.setBackgroundColor(Color.BLACK);          //当前页面的layout
                s = 0;
            } else {
                showToolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2));
                titleShower.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
                shower.setBackgroundColor(Color.WHITE);
                s = 1;
            }
        }
        return true;
    }

  隐藏和显示时都加入了属性动画,慢慢地隐藏。

 

转载于:https://www.cnblogs.com/rewufu/p/4626953.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值