摘要:布局如下代碼中使用方法如下方法實(shí)現(xiàn)如下三自定義選擇器自定義選擇器,可以更加友好的跟用戶進(jìn)行交互。同時(shí)期待您的關(guān)注,感謝您的閱讀,謝謝
極力推薦文章:歡迎收藏
Android 干貨分享
本篇文章主要介紹 Android 開(kāi)發(fā)中的部分知識(shí)點(diǎn),通過(guò)閱讀本篇文章,您將收獲以下內(nèi)容:
一、Button 的繼承關(guān)系一、Button 的繼承關(guān)系
二、Button 簡(jiǎn)單使用舉例
三、自定義 Button 選擇器
四、Button 點(diǎn)擊事件
五、onClick屬性 實(shí)現(xiàn)點(diǎn)擊事件
Button 繼承 TextView,具體關(guān)系如下:
java.lang.Object ???? android.view.View ? ???? android.widget.TextView ? ? ???? android.widget.Button二、Button 簡(jiǎn)單使用舉例
使用 xml 布局跟java代碼動(dòng)態(tài)設(shè)置TextView。
1.xml 布局如下:
java代碼中使用方法如下:
Button OnClickListener方法實(shí)現(xiàn)如下:
public class MyActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_layout_id); final Button button = findViewById(R.id.button_id); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Code here executes on main thread after user presses button } }); } }三、 自定義 Button 選擇器
自定義Button 選擇器,可以更加友好的跟用戶進(jìn)行交互。
xml 布局使用
2.Button 背景選擇器實(shí)現(xiàn)
java 代碼中點(diǎn)擊實(shí)現(xiàn) 效果
public class ButtonMethod extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_button); // 一、自定義Button背景選擇器、匿名內(nèi)部類實(shí)現(xiàn)點(diǎn)擊事件 Button mBtnSelector = (Button) findViewById(R.id.btn_selector); mBtnSelector.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(ButtonMethod.this, "你點(diǎn)擊了按鈕選擇器", 1).show(); } }); // 一、自定義Button背景選擇器、匿名內(nèi)部類實(shí)現(xiàn)點(diǎn)擊事件 } }
4. Button 正常以及獲取焦點(diǎn)圖片素材
四、Button 點(diǎn)擊事件xml 布局使用
java 代碼中點(diǎn)擊實(shí)現(xiàn) 效果
public class ButtonMethod extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_button); // 二、按鈕點(diǎn)擊事件 實(shí)現(xiàn) Button mButton = (Button) findViewById(R.id.btn_test); BtnClick mBtnClick = new BtnClick(); mButton.setOnClickListener(mBtnClick); // 二、按鈕點(diǎn)擊事件 實(shí)現(xiàn) } // 二、按鈕點(diǎn)擊事件 實(shí)現(xiàn) class BtnClick implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(ButtonMethod.this, "你點(diǎn)擊了按鈕點(diǎn)擊事件 實(shí)現(xiàn)", 1).show(); } } // 二、按鈕點(diǎn)擊事件 實(shí)現(xiàn) }五、onClick 屬性 實(shí)現(xiàn)點(diǎn)擊事件
xml 布局使用
java 代碼中點(diǎn)擊實(shí)現(xiàn) 效果
public class ButtonMethod extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_button); } // 三、使用 onClick 實(shí)現(xiàn)點(diǎn)擊事件 public void BtnTestonClick(View view) { Toast.makeText(this, "你點(diǎn)擊了onClick屬性按鈕", 1).show(); } // 三、使用 onClick 實(shí)現(xiàn)點(diǎn)擊事件 }
實(shí)現(xiàn)效果如下:
至此,本篇已結(jié)束,如有不對(duì)的地方,歡迎您的建議與指正。同時(shí)期待您的關(guān)注,感謝您的閱讀,謝謝!
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/75854.html
摘要:的工作過(guò)程的處理主要過(guò)程解析轉(zhuǎn)換生成。代碼轉(zhuǎn)換處理,處理工具插件等就是在這個(gè)階段進(jìn)行代碼轉(zhuǎn)換,返回新的。若感興趣了解更多內(nèi)容,插件中文開(kāi)發(fā)文檔提供了很多詳細(xì)資料。 Babel簡(jiǎn)介 Babel是Javascript編譯器,是種代碼到代碼的編譯器,通常也叫做『轉(zhuǎn)換編譯器』。 Babel的工作過(guò)程 Babel的處理主要過(guò)程:解析(parse)、轉(zhuǎn)換(transform)、生成(generat...
摘要:在經(jīng)常使用,效果跟效果類似,不同點(diǎn)在于可以控制顯示的位置,比如底部顯示等。至此,本篇已結(jié)束,如有不對(duì)的地方,歡迎您的建議與指正。同時(shí)期待您的關(guān)注,感謝您的閱讀,謝謝 showImg(https://segmentfault.com/img/remote/1460000019975019?w=157&h=54); 極力推薦文章:歡迎收藏Android 干貨分享 showImg(http...
閱讀 3134·2021-09-22 15:54
閱讀 4023·2021-09-09 11:34
閱讀 1797·2019-08-30 12:48
閱讀 1186·2019-08-30 11:18
閱讀 3465·2019-08-26 11:48
閱讀 943·2019-08-23 17:50
閱讀 2145·2019-08-23 17:17
閱讀 1270·2019-08-23 17:12