仿照网易云和QQ音乐的锁屏效果
音乐app锁屏效果
参考网址:http://www.android100.org/html/201509/01/178176.html
使用三方侧滑库: https://github.com/ikew0ng/SwipeBackLayout
自己实现代码:
public class MyService extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onCreate() {
super.onCreate();
ScreenReceiver screenReceiver = new ScreenReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);
registerReceiver(screenReceiver, filter);
}
public class ScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_SCREEN_OFF.equals(action)) {
Log.e("tzhhh","锁屏了");
} else if (Intent.ACTION_SCREEN_ON.equals(action)) {
Intent lockscreen = new Intent(MyService.this, LockScreenActivity.class);
lockscreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(lockscreen);
System.out.println("屏幕开启了");
}
}
}
}
public class LockScreenActivity extends SwipeBackActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setContentView(R.layout.activity_lock);
SwipeBackLayout swipeBackLayout = getSwipeBackLayout();
swipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
}
}
android:name=".LockScreenActivity"
android:excludeFromRecents="true"
android:exported="false"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:taskAffinity="com.package.name.lockscreen"
android:theme="@style/LockScreenBase"
android:noHistory="true"/>
true
@android:color/transparent
@null
true
false
@null
@null