自己寫東西的時候,在TextView上添加了onClick去增加點擊事件,去跳轉另一個Activity,運行後結果點擊無效,添加Toast,Toast也不顯示,代碼如下:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content
android:text="Hello World!"
android:onClick="toSecond"/>
在網上找了一下 ,發現TextView默認clickable是false的,所以在上面代碼中加一句android:clickable="true"就可以了:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content
android:text="Hello World!"
android:onClick="toSecond"
android:clickable="true"/>
這樣,TextView使用onClick處理點擊事件就可以了。