Я знаю, что плавающие окна - это сервисы ... Но есть ли способ конвертировать действие / фрагмент в плавающее окно?
Мой пример кода FloatingWindow
public class FloatingWindow extends Service{
WindowManager wm;
LinearLayout ll;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
ll = new LinearLayout(this);
ll.setBackgroundColor(Color.RED);
LinearLayout.LayoutParams layoutParameteres = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 400);
ll.setBackgroundColor(Color.argb(66,255,0,0));
ll.setLayoutParams(layoutParameteres);
final WindowManager.LayoutParams parameters = new WindowManager.LayoutParams(
500, 200, WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
parameters.gravity = Gravity.CENTER | Gravity.CENTER;
parameters.x = 0;
parameters.y = 0;
Button stop = new Button(this);
stop.setText("Stop");
ViewGroup.LayoutParams btnParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
stop.setLayoutParams(btnParameters);
ll.addView(stop);
wm.addView(ll, parameters);
ll.setOnTouchListener(new View.OnTouchListener() {
WindowManager.LayoutParams updatedParameters = parameters;
double x;
double y;
double pressedX;
double pressedY;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x = updatedParameters.x;
y = updatedParameters.y;
pressedX = event.getRawX();
pressedY = event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
updatedParameters.x = (int) (x + (event.getRawX() - pressedX));
updatedParameters.y = (int) (y + (event.getRawY() - pressedY));
wm.updateViewLayout(ll, updatedParameters);
default:
break;
}
return false;
}
});
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
wm.removeView(ll);
stopSelf();
System.exit(0);
}
});
}
@Override
public void onDestroy() {
super.onDestroy();
stopSelf();
}
Итак, у меня есть действие, и я хочу преобразовать его в службу плавающих окон ...... это возможно как-то? Пожалуйста, помогите мне ...... Спасибо ......
Error
На линии - myview = li.inflate(R.layout.activity_customize, null); //
ваш макет здесь
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:id="@+id/actionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/black">
<TextView
android:textColor="@color/white"
android:textSize="20dp"
android:text="Customise"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_below="@+id/actionBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_below="@+id/actionBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/color"
android:paddingVertical="10dp"
android:paddingHorizontal="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="25dp"
android:layout_centerVertical="true"
android:textColor="@color/white"
android:text="Color"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/font"
android:paddingVertical="10dp"
android:paddingHorizontal="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="25dp"
android:layout_centerVertical="true"
android:textColor="@color/white"
android:text="Font"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/size"
android:paddingVertical="10dp"
android:paddingHorizontal="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="25dp"
android:layout_centerVertical="true"
android:textColor="@color/white"
android:text="Size"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Это было самое простое действие в моем проекте, поэтому пробовал с этим