小编yaw*_*ers的帖子

用于自定义视图的Android onTouchEvent

我创建了一个View在自定义内部显示自定义的服务LinearLayout.该服务工作正常,并View显示在屏幕上,但我无法接收ViewLinearLayout接收任何触摸事件(我只是希望其中一个接收触摸事件,我不关心哪个).这就是我所拥有的:

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)

java android

5
推荐指数
1
解决办法
8708
查看次数

Android:服务“尚未绑定”但 onBind() 被调用?

我正在尝试制作一个按钮来更改 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)

android android-service android-activity

2
推荐指数
1
解决办法
1853
查看次数

标签 统计

android ×2

android-activity ×1

android-service ×1

java ×1