安卓的安卓悬浮球软件怎么设置的?

miui8悬浮球怎么开 小米miui8悬浮球开启方法教程
时间: 8:51:59来源:作者:落野(0)
  miui8悬浮球怎么开?小米miui8悬浮球开启方法教程。小米miui8系统是小米官方在今年5月10日夏季发布会上发布的小米miui系统的最新版,小米miui8系统增加了许多强大的功能,如下面小编要给大家讲的悬浮球功能,那么miui8悬浮球怎么开?让小编告诉大家小米miui8悬浮球开启方法教程吧。  一、这个功能默认系统是没有开启的,首先我们需要进入MIUI 8主界面,找到【设置】选项  二、进入到设置界面之后,找到【其他高级设置】选项,点击进入即可看到【悬浮球】一栏  三、最后进入到【悬浮球】设置界面,我们会看到【打开悬浮球】右侧的按钮点击一下即可开启  四、打开悬浮球之后回到桌面,我们会看到桌面有一个黑色的悬浮按钮,点击一下即可看到有一个预设的几个快捷菜单――锁屏、截屏、主页、静音、响铃和返回。  五、除了点击悬浮球可以触发相应功能之外,还能够通过菜单方向进行滑动也可直接触发,也就是所谓的手势操作。了解最新miui8的资讯,扫描或关注微信号:azpc6com匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。&nbsp&#8250&nbsp&nbsp&#8250&nbsp
android悬浮按钮(Floating action button)的两种实现方法
最近中有很多新的设计规范被引入,最流行的莫过于被称作的设计了,是指一种操作按钮,它不是放在actionbar中,而是直接在可见的UI布局中(当然这里的UI指的是setContentView所管辖的范围)。因此它更容易在代码中被获取到(试想如果你要在actionbar中获取一个菜单按钮是不是很难?),往往主要用于一个界面的主要操作,比如在email的邮件列表界面,promoted action可以用于接受一个新邮件。promoted action在外观上其实就是一个悬浮按钮,更常见的是漂浮在界面上的圆形按钮,一般我直接将promoted action称作悬浮按钮,英文名称Float Action Button 简称(FAB,不是FBI哈)。float action button是android l中的产物,但是我们也可以在更早的版本中实现。假设我这里有一个列表界面,我想使用float action button代表添加新元素的功能,界面如下:要实现float action button可以有多种方法,一种只适合android L,另外一种适合任意版本。用实现这种方式其实是在ImageButton的属性中使用了android L才有的一些特性:&ImageButton
android:layout_width="56dp"
android:layout_height="56dp"
android:src="@drawable/plus"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:tint="@android:color/white"
android:id="@+id/fab"
android:elevation="1dp"
android:background="@drawable/ripple"
android:stateListAnimator="@anim/fab_anim"
/&仔细一点,你会发现我们将这个ImageButton放到了布局的右下角,为了实现float action button应该具备的效果,需要考虑以下几个方面:???背景上我们使用来增强吸引力。注意上面的xml代码中我们将设置成了 ,的定义如下:&ripple xmlns:android="/apk/res/android" android:color="?android:colorControlHighlight"&
&shape android:shape="oval"&
&solid android:color="?android:colorAccent" /&
&/ripple&既然是悬浮按钮,那就需要强调维度上面的感觉,当按钮被按下的时候,按钮的阴影需要扩大,并且这个过程是渐变的,我们使用属性动画去改变。&selector xmlns:android="/apk/res/android"&
android:state_enabled="true"
android:state_pressed="true"&
&objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueFrom="@dimen/start_z"
android:valueTo="@dimen/end_z"
android:valueType="floatType" /&
&objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueFrom="@dimen/end_z"
android:valueTo="@dimen/start_z"
android:valueType="floatType" /&
&/selector&使用自定义控件的方式实现悬浮按钮这种方式不依赖于,而是码代码。首先定义一个这样的类:public class CustomFAB extends ImageButton {
}然后是读取一些自定义的属性(假设你了解styleable的用法)private void init(AttributeSet attrSet) {
Resources.Theme theme = ctx.getTheme();
TypedArray arr = theme.obtainStyledAttributes(attrSet, R.styleable.FAB, 0, 0);
setBgColor(arr.getColor(R.styleable.FAB_bg_color, Color.BLUE));
setBgColorPressed(arr.getColor(R.styleable.FAB_bg_color_pressed, Color.GRAY));
StateListDrawable sld = new StateListDrawable();
sld.addState(new int[] {android.R.attr.state_pressed}, createButton(bgColorPressed));
sld.addState(new int[] {}, createButton(bgColor));
setBackground(sld);
catch(Throwable t) {}
arr.recycle();
}在中我们需要加入如下代码,一般是在文件中。&?xml version="1.0" encoding="utf-8"?&
&resources&
&declare-styleable name="FAB"&
&!-- Background color --&
&attr name="bg_color" format="color|reference"/&
&attr name="bg_color_pressed" format="color|reference"/&
&/declare-styleable&
&/resources&使用来实现不同状态下的背景private Drawable createButton(int color) {
OvalShape oShape = new OvalShape();
ShapeDrawable sd = new ShapeDrawable(oShape);
setWillNotDraw(false);
sd.getPaint().setColor(color);
OvalShape oShape1 = new OvalShape();
ShapeDrawable sd1 = new ShapeDrawable(oShape);
sd1.setShaderFactory(new ShapeDrawable.ShaderFactory() {
public Shader resize(int width, int height) {
LinearGradient lg = new LinearGradient(0,0,0, height,
new int[] {
Color.WHITE,
Color.GRAY,
Color.DKGRAY,
Color.BLACK
}, null, Shader.TileMode.REPEAT);
LayerDrawable ld = new LayerDrawable(new Drawable[] { sd1, sd });
ld.setLayerInset(0, 5, 5, 0, 0);
ld.setLayerInset(1, 0, 0, 5, 5);
}最后将控件放中:&RelativeLayout xmlns:android="/apk/res/android"
xmlns:tools="/tools"
xmlns:custom="/apk/res/com.survivingwithandroid.fab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity"&
&com.survivingwithandroid.fab.CustomFAB
android:layout_width="56dp"
android:layout_height="56dp"
android:src="@android:drawable/ic_input_add"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
custom:bg_color="@color/light_blue"
android:tint="@android:color/white"
&/RelativeLayout&项目的源码下载:
上一篇: Android5.0 Lollipop 的 sdk 发布以后,我就希望兼容包中也包含了新的 Material Design 主题,幸运的是的确如此。 这个新的主题包含在 AppCompat 21 中,所以需要注意的是如果你要将 Material Design 运用到以前的项目中,需要做点额外的工作。 本文演示用最
下一篇: 做Android应用开发的同学们相信对“缓存”这个词不陌生,缓存可能有多方面的概念,这里大概列举下程序开发的缓存大概有哪些: 1.服务端控制缓存 如volley请求库,便是通过服务端的“Cache-Control”和“max-age”来告诉客户端有没有缓存以及缓存的时间,也是1354人阅读
自定义控件(1)
获取windowManager 设定WindowManager.LayoutParams使窗口悬浮
主要涉及的值如下,其中
params.type = WindowManager.LayoutParams.TYPE_APPLICATION
设置悬浮窗在应用内,在弹出dialog会悬浮在dialog下方,如果将这个值设置为TYPE_PHONE那么会悬浮在屏幕最上方,回到桌面后,如果应用没有退出悬浮球还是会出现在桌面上,所以如果要开发桌面悬浮球可以这样设置。
WindowManager.LayoutParams params
params = new WindowManager.LayoutParams()
params.type = WindowManager.LayoutParams.TYPE_APPLICATION
params.format = PixelFormat.TRANSLUCENT
params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
params.gravity = Gravity.LEFT | Gravity.TOP
params.width = viewWidth
params.height = viewHeight
params.x = 0
params.y = screenHeight / 3
windowManager.addView(*****,params)
import android.content.C
import android.graphics.PixelF
import android.os.B
import android.util.AttributeS
import android.util.DisplayM
import android.view.D
import android.view.G
import android.view.MotionE
import android.view.V
import android.view.WindowM
import android.widget.LinearL
import java.lang.reflect.F
import java.lang.reflect.M
* Created by fanweichao on .
public class FloatView extends LinearLayout {
private Context mC
private WindowManager windowM
private View floatV
public int viewW
public int viewH
WindowManager.LayoutP
private float xInS
private float yInS
private float xInV
private float yInV
private int screenW
private int screenH
private static int historyX = 0;
private static int historyY = 0;
private static float historyAlpha = 1;
private static String histotyO
private Runnable mHideHalfC
* 记录手指按下时在屏幕上的横坐标的值
private float xDownInS
* 记录手指按下时在屏幕上的纵坐标的值
private float yDownInS
* 状态栏的高度
private int statusBarH
private OnFloatViewClickListener onFloatViewClickL
public FloatView(Context context) {
this(context,null);
public FloatView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext =
private void init() {
viewWidth = Utils.dip2px(mContext,50);
viewHeight = Utils.dip2px(mContext,50);
windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
screenWidth = windowManager.getDefaultDisplay().getWidth();
screenHeight = windowManager.getDefaultDisplay().getHeight();
floatView = View.inflate(mContext,R.layout.******,this);
params = new WindowManager.LayoutParams();
params.type = WindowManager.LayoutParams.TYPE_APPLICATION;
params.format = PixelFormat.TRANSLUCENT;
params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
params.gravity = Gravity.LEFT | Gravity.TOP;
params.width = viewW
params.height = viewH
setViewAlpha(historyAlpha);
if (historyX == 0 && historyY == 0){
params.x = 0;
params.y = screenHeight / 3;
if (historyX &screenWidth-viewWidth/2 || historyY &screenHeight -viewHeight/2){
params.x = 0;
params.y = screenHeight / 3;
historyX = params.x;
historyY = params.y;
params.x = historyX;
params.y = historyY;
windowManager.addView(this,params);
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
setViewAlpha(1);
removeCallbacks(mHideHalfCallback);
xInScreen = event.getRawX();
yInScreen = event.getRawY() - getStatusBarHeight();
xDownInScreen = event.getRawX();
yDownInScreen = event.getRawY() - getStatusBarHeight();
xInView = event.getX();
yInView = event.getY();
case MotionEvent.ACTION_MOVE:
xInScreen = event.getRawX();
yInScreen = event.getRawY() - getStatusBarHeight();
updateViewPosition();
case MotionEvent.ACTION_UP:
if (Math.abs(xDownInScreen-xInScreen)&20 && Math.abs(yDownInScreen-yInScreen)&20){
if (null != onFloatViewClickListener){
onFloatViewClickListener.onFloatViewClick();
stepAside();
return true;
private void stepAside() {
inWitchSide = 0;
float viewCenterX = params.x + viewWidth/2;
float viewCenterY = params.y + viewHeight/2;
float dxLeft = viewCenterX;
float dyUp = viewCenterY;
float dxRight
= screenWidth - dxL
float dyDown = screenHeight -dyUp;
float result = getMin(dxLeft,dyUp,dxRight,dyDown);
if (result == dxLeft){
params.x = 0;
inWitchSide = 0;
}else if (result == dxRight){
params.x = screenWidth-viewW
inWitchSide = 1;
}else if (result == dyUp){
params.y = 0;
inWitchSide = 2;
params.y = screenHeight-viewHeight-getStatusBarHeight();
inWitchSide = 3;
windowManager.updateViewLayout(this, params);
historyX = params.x;
historyY = params.y;
hideHalf(inWitchSide);
private void hideHalf(final int inWitchSide) {
mHideHalfCallback = new HideHalfCallback(inWitchSide);
postDelayed(mHideHalfCallback,1000);
private void updateViewPosition() {
params.x = (int) (xInScreen - xInView);
params.y = (int) (yInScreen - yInView);
if (params.x &0){
params.x = 0;
if (params.y & 0){
if ((params.x + viewWidth) & screenWidth){
params.x = screenWidth -viewW
if (params.y + viewHeight & screenHeight -getStatusBarHeight()){
params.y = screenHeight - getStatusBarHeight() -viewH
windowManager.updateViewLayout(this, params);
historyX = params.x;
historyY = params.y;
private int getStatusBarHeight() {
if (statusBarHeight == 0) {
Class&?& c = Class.forName("com.android.internal.R$dimen");
Object o = c.newInstance();
Field field = c.getField("status_bar_height");
int x = (Integer) field.get(o);
statusBarHeight = getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
return statusBarH
private float getMin(float dxLeft, float dyUp, float dxRight, float dyDown){
float a = Math.min(dxLeft,dyUp);
float b = Math.min(dxRight,dyDown);
float c = Math.min(a,b);
int getBottomStatusHeight(Context context){
int totalHeight = getDpi(context);
int contentHeight = getScreenHeight(context);
return totalHeight
- contentH
int getDpi(Context context){
int dpi = 0;
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
@SuppressWarnings("rawtypes")
c = Class.forName("android.view.Display");
@SuppressWarnings("unchecked")
Method method = c.getMethod("getRealMetrics",DisplayMetrics.class);
method.invoke(display, displayMetrics);
dpi=displayMetrics.heightP
}catch(Exception e){
e.printStackTrace();
int getScreenHeight(Context context)
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.heightP
int getScreenWidth(Context context)
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.widthP
public void showView(){
windowManager.addView(this,params);
public void setOnFloatViewClickListener(OnFloatViewClickListener onFloatViewClickListener) {
this.onFloatViewClickListener = onFloatViewClickL
public interface OnFloatViewClickListener{
void onFloatViewClick();
public void removeView(){
windowManager.removeView(this);
}catch (Exception e){
removeCallbacks(mHideHalfCallback);
mHideHalfCallback = null;
windowManager = null;
params = null;
public void setViewAlpha(float f){
if (Build.VERSION.SDK_INT &= Build.VERSION_CODES.HONEYCOMB) {
setAlpha(f);
historyAlpha =
private class HideHalfCallback implements Runnable{
int inWitchS
public HideHalfCallback(int inWitchSide){
this.inWitchSide = inWitchS
public void run() {
if (null != params && null != windowManager){
if (inWitchSide == 0){
params.x = -viewWidth/2;
}else if (inWitchSide == 1){
params.x = screenWidth-viewWidth/2;
}else if (inWitchSide == 2){
params.y = -viewHeight/2;
}else if (inWitchSide == 3){
params.y =
screenHeight - viewHeight/2 - getStatusBarHeight();
windowManager.updateViewLayout(FloatView.this, params);
setViewAlpha(0.5f);
historyX = params.x;
historyY = params.y;
public void setVisibility(int visibility) {
super.setVisibility(visibility);
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:10416次
排名:千里之外
原创:13篇
(1)(3)(1)(2)(1)(2)(3)

我要回帖

更多关于 安卓悬浮球源码 的文章

 

随机推荐