本文實(shí)例講述了Android編程之ActionBar Tabs用法。分享給大家供大家參考,具體如下:
成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括南陽網(wǎng)站建設(shè)、南陽網(wǎng)站制作、南陽網(wǎng)頁(yè)制作以及南陽網(wǎng)絡(luò)營(yíng)銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,南陽網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到南陽省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
這里主要實(shí)現(xiàn)用Tab切換不同的Fragment,點(diǎn)擊View顯示or隱藏ActionBar,把ActionBar 設(shè)為透明,使界面更加友好,詳細(xì)代碼見資源里的ActionBarTabs。
ActionBar Tab主要用于Fragment之間的切換,其必須要設(shè)置ActionBar.TabListener,詳細(xì)代碼如下
ActionBarActivity.Java:
import android.app.ActionBar; import android.app.Activity; import android.app.FragmentTransaction; import android.app.ActionBar.Tab; import android.os.Bundle; import android.os.CountDownTimer; import android.view.MotionEvent; import android.view.Window; public class ActionBarActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //使ActionBar變得透明 requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); setContentView(R.layout.main); final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // remove the activity title to make space for tabs actionBar.setDisplayShowTitleEnabled(false); AFragment aFragment = new AFragment(); actionBar.addTab(actionBar.newTab().setText("Tab-A") .setTabListener(new ListenerA(aFragment))); BFragment bFragment = new BFragment(); actionBar.addTab(actionBar.newTab().setText("Tab-B") .setTabListener(new ListenerB(bFragment))); } //點(diǎn)擊顯示or隱藏ActionBar public boolean onTouchEvent(MotionEvent event){ ActionBar bar = getActionBar(); switch(event.getAction()){ case MotionEvent.ACTION_UP: if(bar.isShowing()) bar.hide(); else bar.show(); break; default: break; } return true; } private class ListenerA implements ActionBar.TabListener { private AFragment mFragment; // Called to create an instance of the listener when adding a new tab public ListenerA(AFragment fragment) { mFragment = fragment; } public void onTabSelected(Tab tab, FragmentTransaction ft) { ft.add(R.id.fragment, mFragment, null); } public void onTabUnselected(Tab tab, FragmentTransaction ft) { ft.remove(mFragment); } public void onTabReselected(Tab tab, FragmentTransaction ft) { // do nothing } } } private class ListenerB implements ActionBar.TabListener { private BFragment mFragment; // Called to create an instance of the listener when adding a new tab public ListenerB(BFragment fragment) { mFragment = fragment; } public void onTabSelected(Tab tab, FragmentTransaction ft) { ft.add(R.id.fragment, mFragment, null); } public void onTabUnselected(Tab tab, FragmentTransaction ft) { ft.remove(mFragment); } public void onTabReselected(Tab tab, FragmentTransaction ft) { // do nothing } } } }
其中涉及到兩個(gè)Fragment,在前面Fragment的筆記中講過,這里就不再贅述。類AFragment實(shí)現(xiàn)如下,BFragment實(shí)現(xiàn)與這類似:
public class AFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.alayout, container, false); } }
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
分享名稱:Android編程之ActionBarTabs用法實(shí)例分析
文章地址:http://aaarwkj.com/article2/ijhcic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、網(wǎng)站策劃、移動(dòng)網(wǎng)站建設(shè)、ChatGPT、軟件開發(fā)、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)