当前位置: 首页>>代码示例>>Java>>正文


Java Button.setOnTouchListener方法代码示例

本文整理汇总了Java中android.widget.Button.setOnTouchListener方法的典型用法代码示例。如果您正苦于以下问题:Java Button.setOnTouchListener方法的具体用法?Java Button.setOnTouchListener怎么用?Java Button.setOnTouchListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.Button的用法示例。


在下文中一共展示了Button.setOnTouchListener方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.widget.Button; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_overshoot);
    
    final Button clickMeButton = (Button) findViewById(R.id.clickMe);
    clickMeButton.animate().setDuration(200);
    
    clickMeButton.setOnTouchListener(new View.OnTouchListener() {
        
        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
                clickMeButton.animate().setInterpolator(sDecelerator).
                        scaleX(.7f).scaleY(.7f);
            } else if (arg1.getAction() == MotionEvent.ACTION_UP) {
                clickMeButton.animate().setInterpolator(sOvershooter).
                        scaleX(1f).scaleY(1f);
            }
            return false;
        }
    });
    
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:25,代码来源:LiveButton.java

示例2: showWindow

import android.widget.Button; //导入方法依赖的package包/类
private void showWindow() {
    mFloatingButton = new Button(this);
    mFloatingButton.setText("button");
    mFloatingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "我是window", Toast.LENGTH_LONG).show();
        }
    });
    mLayoutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT
            ,WindowManager.LayoutParams.WRAP_CONTENT, 0, 0, PixelFormat.TRANSLUCENT);
    mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
    mLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
    mLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    mLayoutParams.x = 100;
    mLayoutParams.y = 300;
    mFloatingButton.setOnTouchListener(this);
    mWindowManager.addView(mFloatingButton, mLayoutParams);
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:22,代码来源:TestWindowActivity.java

示例3: onCreate

import android.widget.Button; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    W = (Button)(findViewById(R.id.W));
    E = (Button)(findViewById(R.id.E));
    N = (Button)(findViewById(R.id.N));
    S = (Button)(findViewById(R.id.S));

    SW = (Button)(findViewById(R.id.SW));
    SE = (Button)(findViewById(R.id.SE));
    NE = (Button)(findViewById(R.id.NE));
    NW = (Button)(findViewById(R.id.NW));

    toBluetooth = (Button)(findViewById(R.id.Bluetooth));

    init(set);

    W.setOnTouchListener(new myHandler(1));
    E.setOnTouchListener(new myHandler(2));
    N.setOnTouchListener(new myHandler(3));
    S.setOnTouchListener(new myHandler(4));

    NE.setOnTouchListener(new myHandler(5));
    NW.setOnTouchListener(new myHandler(6));
    SW.setOnTouchListener(new myHandler(7));
    SE.setOnTouchListener(new myHandler(8));

    toBluetooth.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            startActivityForResult(new Intent(MainActivity.this , Bluetooth.class) , 1);
        }
    });
}
 
开发者ID:amraboelkher,项目名称:Flame-Detector-RC-Car,代码行数:37,代码来源:MainActivity.java

示例4: initBottomView

import android.widget.Button; //导入方法依赖的package包/类
private void initBottomView() {
        add = (Button) findViewById(R.id.btn_chat_bottom_add);
        emotion = (Button) findViewById(R.id.btn_chat_bottom_emotion);
        input = (EditText) findViewById(R.id.et_chat_bottom_input);
        speak = (Button) findViewById(R.id.btn_chat_bottom_speak);
        send = (Button) findViewById(R.id.btn_chat_bottom_send);
        voice = (Button) findViewById(R.id.btn_chat_bottom_voice);
        keyboard = (Button) findViewById(R.id.btn_chat_bottom_keyboard);
        l1_more = (LinearLayout) findViewById(R.id.l1_chat_bottom_more);
        mViewPager = (ViewPager) findViewById(R.id.vp_chat_bottom_emotion);
        r1_emotion = (RelativeLayout) findViewById(R.id.r1_chat_bottom_emotion);
        l1_add = (LinearLayout) findViewById(R.id.l1_chat_bottom_add);
        picture = (TextView) findViewById(R.id.tv_chat_bottom_picture);
        camera = (TextView) findViewById(R.id.tv_chat_bottom_camera);
        location = (TextView) findViewById(R.id.tv_chat_bottom_location);
        add.setOnClickListener(this);
        emotion.setOnClickListener(this);
        input.addTextChangedListener(this);
        input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                        if (hasFocus) {
                                LogUtil.e("聚焦");
                                scrollToBottom();
                                if (l1_more.getVisibility() == View.VISIBLE) {
                                        l1_more.setVisibility(View.GONE);
                                }
                        }
                }
        });
        voice.setOnClickListener(this);
        send.setOnClickListener(this);
        keyboard.setOnClickListener(this);
        location.setOnClickListener(this);
        picture.setOnClickListener(this);
        camera.setOnClickListener(this);
        speak.setOnTouchListener(this);
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                        mSwipeRefreshLayout.setRefreshing(true);
                        BaseMessage message = mAdapter.getData(0);
                        LoadMessage(message);
                }
        });
}
 
开发者ID:HelloChenJinJun,项目名称:TestChat,代码行数:47,代码来源:ChatActivity.java

示例5: initUi

import android.widget.Button; //导入方法依赖的package包/类
@SuppressLint("ShowToast")
private void initUi() {
	mResultEditText = (EditText) findViewById(R.id.edt_result);
	mAuthidEditText = (EditText) findViewById(R.id.set_authId);
	btn_start_record = (Button) findViewById(R.id.isv_reocrd);
	btn_start_record.setOnTouchListener(VocalVerifyDemo.this);
	findViewById(R.id.isv_getpassword).setOnClickListener(VocalVerifyDemo.this);
	findViewById(R.id.isv_search).setOnClickListener(VocalVerifyDemo.this);
	findViewById(R.id.isv_delete).setOnClickListener(VocalVerifyDemo.this);
	findViewById(R.id.isv_identity).setOnClickListener(VocalVerifyDemo.this);


	mToast = Toast.makeText(VocalVerifyDemo.this, "", Toast.LENGTH_SHORT);
	mToast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);

	mProDialog = new ProgressDialog(VocalVerifyDemo.this);
	mProDialog.setCancelable(true);
	mProDialog.setTitle("请稍候");
	// cancel进度框时,取消正在进行的操作
	mProDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

		@Override
		public void onCancel(DialogInterface dialog) {
			if (null != mIdVerifier) {
				mIdVerifier.cancel();
			}
		}
	});

	// 密码选择RadioGroup初始化
	mSstTypeGroup = (RadioGroup) findViewById(R.id.vocal_radioGroup1);
	mSstTypeGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			if( null == mIdVerifier ){
				// 创建单例失败,与 21001 错误为同样原因,参考 http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=9688
				showTip( "创建对象失败,请确认 libmsc.so 放置正确,且有调用 createUtility 进行初始化" );
				return;
			}

			// 取消之前操作
			if (mIdVerifier.isWorking()) {
				mIdVerifier.cancel();
			}
			cancelOperation();

			switch (checkedId) {
				case R.id.vocal_radioVerify:
					// 设置会话类型为验证
					mSST = SST_VERIFY;
					mVerifyNumPwd = VerifierUtil.generateNumberPassword(8);

					StringBuffer strBuffer = new StringBuffer();
					strBuffer.append("您的验证密码:" + mVerifyNumPwd + "\n");
					strBuffer.append("请长按“按住说话”按钮进行验证!\n");
					mResultEditText.setText(strBuffer.toString());
					break;
				case R.id.vocal_radioEnroll:
					// 设置会话类型为验证
					mSST = SST_ENROLL;

					if (null == mNumPwdSegs) {
						// 首次注册密码为空时,调用下载密码
						downloadPwd();
					} else {
						mResultEditText.setText("请长按“按住说话”按钮进行注册\n");
					}
					break;
				default:
					break;
			}
		}
	});
}
 
开发者ID:SoulEaterVTT,项目名称:KotlinStudy,代码行数:75,代码来源:VocalVerifyDemo.java

示例6: onCreate

import android.widget.Button; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_window);

    findViewById(R.id.btn_add_view).setOnClickListener(this);
    findViewById(R.id.btn_remove_view).setOnClickListener(this);

    windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    layoutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT
            , WindowManager.LayoutParams.WRAP_CONTENT, 0, 0, PixelFormat.TRANSLUCENT);
    layoutParams.x = 100;
    layoutParams.y = 100;
    layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION;

    button = new Button(this);
    button.setText("Button");

    button.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_MOVE:
                    if (windowManager != null) {
                        layoutParams.x = (int) event.getRawX();
                        layoutParams.y = (int) event.getRawY();
                        windowManager.updateViewLayout(button, layoutParams);
                    }
                    break;
            }

            return false;
        }
    });
}
 
开发者ID:guoxiaoxing,项目名称:android-open-source-project-analysis,代码行数:37,代码来源:WindowActivity.java


注:本文中的android.widget.Button.setOnTouchListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。