修改SystemUI音量界面备忘

来源:互联网 发布:网络剧多少钱一集 编辑:程序博客网 时间:2024/05/17 04:57

一下内容纯属个人备忘之用

seekbar:

1.设置游标:android:thumb="@drawable/ic_volume_thumb"

2.设置layerList(图层):android:progressDrawable="@drawable/yyd_volume_progress"

有三层,底层是background,中层是第二进度条(类似播放器的缓存条),上层是进度条

<?xml version="1.0" encoding="utf-8"?><layer-list    xmlns:android="http://schemas.android.com/apk/res/android">    <item android:id="@*android:id/background">        <shape>            <solid android:color="#ff70777d" />            <corners android:radius="10px"/>        </shape>    </item>    <item android:id="@*android:id/secondaryProgress">        <clip>            <shape>                <solid android:color="#99ffffff" />                <corners android:radius="10px"/>            </shape>        </clip>    </item>    <item android:id="@*android:id/progress">        <clip>            <shape>                <solid android:color="#fff2c356" />                <corners android:radius="10px"/>            </shape>        </clip>    </item></layer-list>
3.设置progressDrawable的高度和长度,使用view的layout_height和layout_width设置是没有效的。
        android:minHeight="20px"
        android:maxHeight="20px"
        android:minWidth="508px"
        android:maxWidth="508px"


4.android 5.0及以上,seekbar thumb 透明效果出现父布局背景颜色的解决方法

    android:splitTrack="false"

5.定义一个图形背景:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >    <solid android:color="#b22d3246" />    <corners android:radius="57px" /></shape>

6.在设置一个imageview的淡入淡出动画时,使用AlphaAnimation,淡出的时候可以,但是淡入时,

不成功,未找到原因,最后淡入时使用ObjectAnimator,代码如下:

  奇怪的是还要在动画前给view设置一个非0的alpha值

private void showMuteNotificationIcon(View view, int animationDuration){              view.clearAnimation();        view.setVisibility(View.VISIBLE);        if(view.getAlpha() < 0.1){            view.setAlpha(0.1f);        }else{            view.setAlpha(view.getAlpha());        }        Animator anim = ObjectAnimator.ofFloat(view, "alpha", view.getAlpha(), 1f);        anim.setDuration((int)(animationDuration * (1-view.getAlpha())));        anim.start();    }    private void dismissMuteNotificationIcon(final View view, int animationDuration){        if(view.getVisibility() != View.VISIBLE)            return;                AlphaAnimation dismissAlphaAnimation = new AlphaAnimation(view.getAlpha(), 0);        dismissAlphaAnimation.setDuration(animationDuration);        dismissAlphaAnimation.setAnimationListener(new Animation.AnimationListener(){            @Override            public void onAnimationStart(Animation animation) {                // TODO Auto-generated method stub            }            @Override            public void onAnimationEnd(Animation animation) {                // TODO Auto-generated method stub                view.setAlpha(0);                view.setVisibility(View.INVISIBLE);            }            @Override            public void onAnimationRepeat(Animation animation) {                // TODO Auto-generated method stub            }        });        view.clearAnimation();        view.startAnimation(dismissAlphaAnimation);    }


7.弹出一个全屏窗口

new Dialog(context , R.style..MuteTipsDialog),在style.xml文件中继承Theme.NoTitleBar.Fullscreen,定义自己的淡出动画,

设置windowExitAnimation这个属性lp.windowAnimations = R.style.MuteTipsDialog;


设置window这个属性

<style name="MuteTipsDialog" parent="@*android:style/Theme.NoTitleBar.Fullscreen">        <item name="android:windowEnterAnimation">@*android:anim/grow_fade_in_from_bottom</item>        <item name="android:windowExitAnimation">@anim/mute_dialog_animation</item>    </style>

mute_dialog_animation.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <!--<translate        android:duration="300"        android:fromYDelta="0%"        android:toYDelta="200%"/>-->    <alpha        android:duration="1000"        android:fromAlpha="1"        android:toAlpha="0"        android:interpolator="@android:interpolator/linear"/></set>



添加一些flags

window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED  //锁屏时也能弹出
                | WindowManager.LayoutParams.FLAG_FULLSCREEN                                    //全屏标志
                | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);       //硬件加速,没什么必要

注意:设置了某个属性,另外一个属性可能会被enable,即使你没有设置改flag,如:

设置FLAG_NOT_FOCUSABLE 会enable FLAG_NOT_TOUCH_MODAL

 如果需要接收dialog window外的事件,可以设置FLAG_NOT_TOUCH_MODAL和FLAG_WATCH_OUTSIDE_TOUCH

然后在继承Dialog,复写其onTouchEvent,其中判断事件是否来自window区域外:
 if (event.getAction() == MotionEvent.ACTION_OUTSIDE)

如果window是全屏的,还可以在onTouchEvent中调用dismiss()使点击屏幕任意地方都可以消失,或做其他操作

如果只是想要在点击dialog外部,dialog消失的话,只需mDialog.setCanceledOnTouchOutside(true);,注意此时该

dialog接收了window外的事件,并返回了true,那么mDialog.setCanceledOnTouchOutside(true)就无效了;


设置窗口位置:

lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; //向上对齐,水平居中
lp.y = res.getDimensionPixelSize(R.dimen.volume_offset_top);//设置y坐标


还要设置contentview

整体代码如下:

private void createMuteDialog(){        mDialog = new Dialog(mContext,/*android.R.style.Theme_NoTitleBar_Fullscreen*/R.style.MuteTipsDialog)        {                @Override                public boolean dispatchTouchEvent(MotionEvent ev) {                    return super.dispatchTouchEvent(ev);                }                @Override                protected void onStop() {                    super.onStop();                }                @Override                public boolean onTouchEvent(MotionEvent event) {                    if (isShowing()) {                            dismiss();                            return true;                    }                    return false;                }        };        final Window window = mDialog.getWindow();        window.requestFeature(Window.FEATURE_NO_TITLE);        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));        window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);        window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED                | WindowManager.LayoutParams.FLAG_FULLSCREEN                | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);        mDialog.setCanceledOnTouchOutside(true);        final Resources res = mContext.getResources();        final WindowManager.LayoutParams lp = window.getAttributes();        lp.type = WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;        lp.format = PixelFormat.TRANSLUCENT;        lp.setTitle(VolumeDialog.class.getSimpleName());        lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;        lp.y = res.getDimensionPixelSize(R.dimen.volume_offset_top);        lp.windowAnimations = R.style.MuteTipsDialog;        window.setAttributes(lp);        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);        mDialog.setContentView(R.layout.mute_tips_dialog);        mDialog.setOnShowListener(new Dialog.OnShowListener(){            @Override            public void onShow(DialogInterface dialog) {                           }        });    }

窗口布局文件如下:

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#66ffffff">    <RelativeLayout        android:layout_width="600px"        android:layout_height="400px"        android:layout_centerInParent="true"        android:background="@drawable/mute_tips_background">        <ImageView            android:id="@+id/iv_mute"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_centerInParent="true"            android:src="@drawable/mute_tips"/>        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginTop="10dp"            android:layout_below="@id/iv_mute"            android:layout_centerHorizontal="true"            android:textSize="16sp"            android:text="@string/mute_prompt"/>    </RelativeLayout></RelativeLayout>





原创粉丝点击