我创建了一个View在自定义内部显示自定义的服务LinearLayout.该服务工作正常,并View显示在屏幕上,但我无法接收View或LinearLayout接收任何触摸事件(我只是希望其中一个接收触摸事件,我不关心哪个).这就是我所拥有的:
MyLayout.java
public class MyLayout extends LinearLayout {
public MyLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyLayout(Context context) {
super(context);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
onTouchEvent(ev);
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Toast.makeText(this.getContext(), "Touched layout", Toast.LENGTH_SHORT).show();
Log.d("TOUCH", "Touched layout");
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
MyView.java
public class MyViewextends View{
public MyView(Context context, …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个按钮来更改 Android Lollipop 中的中断过滤器(无、优先级、全部)。当我按下按钮时,日志显示W/NotificationListenerService[NotificationService]: Notification listener service not yet bound.并且不会更改中断过滤器。我得到了"NLS Started"和"NLS Bound"日志。为什么它给我这个警告?这是我的代码:
MainActivity.java:
public class MainActivity extends Activity {
private NotificationService notifs;
private ServiceConnection connection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
notifs = new NotificationService();
connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d("NOTIF", "NLS Started");
NotificationService.ServiceBinder binder = (NotificationService.ServiceBinder)service;
notifs = binder.getService();
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.d("NOTIF", "NLS Stopped");
}
};
Intent …Run Code Online (Sandbox Code Playgroud)