如何在Android中使用hover組件監(jiān)控鼠標(biāo)移動(dòng)事件?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
Android之前對(duì)于鼠標(biāo)光標(biāo)事件的監(jiān)控非常少,4.0之后多了一個(gè)hover的組件,此組件可以監(jiān)控鼠標(biāo)光標(biāo)在view上的變化。
代碼如下:
public class HoverDemoActivity extends Activity { private Button btnBottom; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnBottom = (Button) findViewById(R.id.btn_bottom); btnBottom.setOnHoverListener(new OnHoverListener() { @Override public boolean onHover(View v, MotionEvent event) { int what = event.getAction(); switch(what){ case MotionEvent.ACTION_HOVER_ENTER: //鼠標(biāo)進(jìn)入view System.out.println("bottom ACTION_HOVER_ENTER"); break; case MotionEvent.ACTION_HOVER_MOVE: //鼠標(biāo)在view上 System.out.println("bottom ACTION_HOVER_MOVE"); break; case MotionEvent.ACTION_HOVER_EXIT: //鼠標(biāo)離開(kāi)view System.out.println("bottom ACTION_HOVER_EXIT"); break; } return false; } }); } }
分享文章:如何在Android中使用hover組件監(jiān)控鼠標(biāo)移動(dòng)事件-創(chuàng)新互聯(lián)
地址分享:http://chinadenli.net/article22/cdjocc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、網(wǎng)站排名、全網(wǎng)營(yíng)銷(xiāo)推廣、自適應(yīng)網(wǎng)站、虛擬主機(jī)、用戶(hù)體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容