亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 系統 > Android > 正文

Android實現淘寶底部圖標導航欄

2019-10-21 21:32:09
字體:
來源:轉載
供稿:網友

在上一篇中,簡單的使用透明主題的Activity實現了仿微信右側頂部的對話框,上午又花了兩個小時研究了一下淘寶底部的導航欄實現,網上的做法也有很多,今天我就使用一種通過基本控件加上布局的方式,沒有任何的自定義風格,控件等來實現,還是老樣子,先看一下效果圖:

Android,淘寶,圖標,導航欄

下面就來具體看一看如何實現的,還是按照步驟來吧:

繪制主界面

activity_layout.xml代碼如下:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:app="http://schemas.android.com/apk/res-auto"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:fitsSystemWindows="true"  android:orientation="vertical"  tools:context=".MainActivity">   <FrameLayout    android:id="@+id/fragment_container"    android:layout_marginBottom="50dp"    android:layout_width="match_parent"    android:layout_height="match_parent">   </FrameLayout>   <LinearLayout    android:layout_width="match_parent"    android:layout_height="50dp"    android:layout_alignParentBottom="true"    android:background="@color/noCheckedColor">     <RelativeLayout      android:gravity="center"      android:layout_width="wrap_content"      android:layout_height="match_parent">    <ImageView      android:layout_marginTop="5dp"      android:id="@+id/title_image"      android:layout_marginLeft="18dp"      android:layout_width="40dp"      android:layout_height="40dp"      android:background="@drawable/taobao" />       <LinearLayout        android:gravity="center"        android:orientation="vertical"        android:id="@+id/first_page_layout"        android:layout_width="60dp"        android:layout_height="wrap_content">      <ImageView        android:id="@+id/first_page_icon"        android:layout_width="30dp"        android:layout_height="30dp"        android:background="@drawable/firstpage" />       <TextView        android:textColor="#000000"        android:id="@+id/first_page_text"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:gravity="center"        android:text="首頁" />      </LinearLayout>     </RelativeLayout>       <LinearLayout        android:layout_marginLeft="26dp"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal"        android:weightSum="4">         <LinearLayout          android:id="@+id/micro_tao_layout"          android:layout_width="0dp"          android:layout_height="match_parent"          android:layout_weight="1"          android:gravity="center"          android:orientation="vertical">           <ImageView            android:id="@+id/microtao_icon"            android:layout_width="30dp"            android:layout_height="30dp"            android:background="@drawable/microtao" />           <TextView            android:textColor="#000000"            android:id="@+id/microtao_text"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:gravity="center"            android:text="微淘" />        </LinearLayout>         <LinearLayout          android:id="@+id/message_layout"          android:layout_width="0dp"          android:layout_height="match_parent"          android:layout_weight="1"          android:gravity="center"          android:orientation="vertical">           <ImageView            android:id="@+id/message_icon"            android:layout_width="30dp"            android:layout_height="30dp"            android:background="@drawable/message" />           <TextView            android:textColor="#000000"            android:id="@+id/message_text"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:gravity="center"            android:text="消息" />        </LinearLayout>          <LinearLayout          android:id="@+id/buycar_layout"          android:layout_width="0dp"          android:layout_height="match_parent"          android:layout_weight="1"          android:gravity="center"          android:orientation="vertical">           <ImageView            android:id="@+id/buycar_icon"            android:layout_width="30dp"            android:layout_height="30dp"            android:background="@drawable/buycar" />           <TextView            android:textColor="#000000"            android:id="@+id/buycar_text"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:gravity="center"            android:text="購物車" />        </LinearLayout>         <LinearLayout          android:id="@+id/myfile_layout"          android:layout_width="0dp"          android:layout_height="match_parent"          android:layout_weight="1"          android:gravity="center"          android:orientation="vertical">           <ImageView            android:id="@+id/myfile_icon"            android:layout_width="30dp"            android:layout_height="30dp"            android:background="@drawable/myfile" />           <TextView            android:textColor="#000000"            android:id="@+id/myfile_text"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:gravity="center"            android:text="我的淘寶" />        </LinearLayout>      </LinearLayout>    </LinearLayout></RelativeLayout>

界面的邏輯控制Activity:

MainActivity.java代碼:

package com.hfut.enmulatetaobaonavbar; import android.graphics.Color;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentTransaction;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.TextView; import com.hfut.enmulatetaobaonavbar.fragment.BuycarFragment;import com.hfut.enmulatetaobaonavbar.fragment.FirstPageFragment;import com.hfut.enmulatetaobaonavbar.fragment.MessageFragment;import com.hfut.enmulatetaobaonavbar.fragment.MicroTaoFragment;import com.hfut.enmulatetaobaonavbar.fragment.MyfileFragment; /** * @author why * @date 2018-10-3 11:12:39 */public class MainActivity extends AppCompatActivity implements View.OnClickListener {   LinearLayout microTaoLay;  LinearLayout messageLay;  LinearLayout buycarLay;  LinearLayout myfileLay;  LinearLayout firstPageLay;   ImageView microTaoIcon;  ImageView messageIcon;  ImageView buycarIcon;  ImageView myfileIcon;  ImageView firstPageIcon;  ImageView titleImage;   TextView microTaoText;  TextView messageText;  TextView buycarText;  TextView myfileText;    FragmentManager manager;  FragmentTransaction transaction;  Fragment firFragment, microFragment, messageFragment, buycarFragment, myfileFragment;   @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);     manager = getSupportFragmentManager();    transaction = manager.beginTransaction();    firFragment = new FirstPageFragment();    transaction.add(R.id.fragment_container, firFragment);    transaction.commit();    initUI();  }   private void initUI() {    microTaoLay = findViewById(R.id.micro_tao_layout);    messageLay = findViewById(R.id.message_layout);    buycarLay = findViewById(R.id.buycar_layout);    myfileLay = findViewById(R.id.myfile_layout);    firstPageLay = findViewById(R.id.first_page_layout);    firstPageLay.setVisibility(View.INVISIBLE);     microTaoIcon = findViewById(R.id.microtao_icon);    messageIcon = findViewById(R.id.message_icon);    buycarIcon = findViewById(R.id.buycar_icon);    myfileIcon = findViewById(R.id.myfile_icon);    firstPageIcon = findViewById(R.id.first_page_icon);    titleImage = findViewById(R.id.title_image);     microTaoText = findViewById(R.id.microtao_text);    messageText = findViewById(R.id.message_text);    buycarText = findViewById(R.id.buycar_text);    myfileText = findViewById(R.id.myfile_text);     microTaoLay.setOnClickListener(this);    messageLay.setOnClickListener(this);    buycarLay.setOnClickListener(this);    myfileLay.setOnClickListener(this);    firstPageLay.setOnClickListener(this);   }   @Override  public void onClick(View v) {    transaction = manager.beginTransaction();    hideFragment(transaction);//隱藏之前的Fragment    switch (v.getId()) {      case R.id.micro_tao_layout:        microFragment = new MicroTaoFragment();        transaction.add(R.id.fragment_container, microFragment);        transaction.commit();        microTaoIcon.setImageDrawable(getResources().getDrawable(R.drawable.microtao_choosen));        microTaoText.setTextColor(Color.RED);         //顯示首頁布局,隱藏標題淘寶圖片        if (firstPageLay.getVisibility() != View.VISIBLE) {          firstPageLay.setVisibility(View.VISIBLE);          titleImage.setVisibility(View.INVISIBLE);        }         break;      case R.id.message_layout:        messageFragment = new MessageFragment();        transaction.add(R.id.fragment_container, messageFragment);        transaction.commit();        messageIcon.setImageDrawable(getResources().getDrawable(R.drawable.message_choosen));        messageText.setTextColor(Color.RED);         //顯示首頁布局,隱藏標題淘寶圖片        if (firstPageLay.getVisibility() != View.VISIBLE) {          firstPageLay.setVisibility(View.VISIBLE);          titleImage.setVisibility(View.INVISIBLE);        }        break;      case R.id.buycar_layout:        buycarFragment = new BuycarFragment();        transaction.add(R.id.fragment_container, buycarFragment);        transaction.commit();        buycarIcon.setImageDrawable(getResources().getDrawable(R.drawable.buycar_choosen));        buycarText.setTextColor(Color.RED);         //顯示首頁布局,隱藏標題淘寶圖片        if (firstPageLay.getVisibility() != View.VISIBLE) {          firstPageLay.setVisibility(View.VISIBLE);          titleImage.setVisibility(View.INVISIBLE);        }        break;      case R.id.myfile_layout:        myfileFragment = new MyfileFragment();        transaction.add(R.id.fragment_container, myfileFragment);        transaction.commit();        myfileIcon.setImageDrawable(getResources().getDrawable(R.drawable.myfile_choosen));        myfileText.setTextColor(Color.RED);         //顯示首頁布局,隱藏標題淘寶圖片        if (firstPageLay.getVisibility() != View.VISIBLE) {          firstPageLay.setVisibility(View.VISIBLE);          titleImage.setVisibility(View.INVISIBLE);        }        break;       case R.id.first_page_layout:        firFragment = new FirstPageFragment();        transaction.add(R.id.fragment_container, firFragment);        transaction.commit();        firstPageLay.setVisibility(View.INVISIBLE);        titleImage.setVisibility(View.VISIBLE);       default:        break;    }  }   private void hideFragment(FragmentTransaction transaction) {    if (firFragment != null) {      transaction.remove(firFragment);     }    if (microFragment != null) {      transaction.remove(microFragment);      microTaoIcon.setImageDrawable(getResources().getDrawable(R.drawable.microtao));      microTaoText.setTextColor(Color.BLACK);     }    if (messageFragment != null) {      transaction.remove(messageFragment);      messageIcon.setImageDrawable(getResources().getDrawable(R.drawable.message));      messageText.setTextColor(Color.BLACK);    }    if (buycarFragment != null) {      transaction.remove(buycarFragment);      buycarIcon.setImageDrawable(getResources().getDrawable(R.drawable.buycar));      buycarText.setTextColor(Color.BLACK);    }    if (myfileFragment != null) {      transaction.remove(myfileFragment);      myfileIcon.setImageDrawable(getResources().getDrawable(R.drawable.myfile));      myfileText.setTextColor(Color.BLACK);    }  }}

Fragment對應的布局代碼(這里為了簡化,所有Fragment使用的是同一個很簡單的布局):
fragment_layout.xml代碼:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:gravity="center"  android:layout_width="match_parent"  android:layout_height="match_parent">   <TextView    android:gravity="center"    android:id="@+id/tip_message"    android:textSize="30sp"    android:text="首頁"    android:layout_width="wrap_content"    android:layout_height="wrap_content" /> </LinearLayout>

自定義Fragment代碼(這里我就給出一個,其他的完全一樣,只是修改了Fragment布局中的文本內容):
FirstPageFragment.java代碼:

package com.hfut.enmulatetaobaonavbar.fragment; import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.TextView; import com.hfut.enmulatetaobaonavbar.R; /** * author:why * created on: 2018/10/3 12:11 * description: */public class FirstPageFragment extends Fragment {   TextView message;  @Nullable  @Override  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {    View view = inflater.inflate(R.layout.fragment_layout, container, false);    message=view.findViewById(R.id.tip_message);    message.setText("這是首頁");    return view;  }}

上面就是幾個主要的組成部分了,其他的素材就不介紹了,還有就是很多代碼可以優化的地方也沒有做在太多考慮,下面就來說一說幾個需要注意的點:

  • Fragment,FragmentManager,FragmentTransaction的配合使用
  • 淘寶圖標與首頁菜單項的切換
  • Fragment的包不要使用錯了,不是android.app.Fragment
  • 填充FramLayout的時候,注意FragmentTransaction里面的內容的添加與刪除
  • 實現的本質其實就是點擊事件與FramLayout配合Fragment實現的

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产成一区二区| 成人h视频在线观看播放| 亚洲男人天堂2019| 国内揄拍国内精品少妇国语| 国产精品久久久久久久久粉嫩av| 韩国精品久久久999| 日本精品久久中文字幕佐佐木| 国产精品香蕉av| 亚洲另类xxxx| 国内精品小视频| 欧美日韩一区二区免费视频| 国产不卡av在线| 国产日本欧美一区| 91久久精品国产91久久| 欧美性猛交xxxx黑人| 国产精品偷伦视频免费观看国产| 丝袜美腿精品国产二区| 亚洲精品一区二三区不卡| 欧美日韩激情视频8区| 亚洲人成电影网站色…| 国产成人精品电影| 日韩www在线| 精品国产视频在线| 亚洲精品福利视频| 国产亚洲精品美女久久久久| 91av在线看| 欧美在线视频观看| 亚洲国产免费av| 大胆欧美人体视频| 亚洲国产天堂网精品网站| 亚洲毛片在线观看| 91av视频在线| 久久免费高清视频| 欧美大尺度在线观看| 亚洲资源在线看| 九九热r在线视频精品| 亚洲一区二区三区四区在线播放| 亚洲欧美中文另类| 欧美黑人xxxx| 亚洲成年网站在线观看| 亚洲视频日韩精品| 亚洲视频777| 欧美高清一级大片| 亚洲xxxx做受欧美| 日韩av在线免费观看一区| 欧美性xxxxhd| 色婷婷综合成人av| 欧美亚洲国产视频| 色午夜这里只有精品| 日韩精品视频免费在线观看| 色综合久久天天综线观看| 2025国产精品视频| 91免费电影网站| 91香蕉嫩草神马影院在线观看| 久久久精品免费视频| 国产精品大片wwwwww| 国产精品日韩在线播放| 欧美精品videos性欧美| 国外成人在线播放| 欧美日本高清视频| 国产亚洲精品久久久优势| 亚洲国产精品人久久电影| 国产精品激情av电影在线观看| 欧美一级大片在线免费观看| 亚洲精品91美女久久久久久久| 亚洲精品影视在线观看| 欧美日韩在线影院| 7m第一福利500精品视频| 欧美成人手机在线| 欧洲成人在线观看| 亚洲精品国产精品乱码不99按摩| 在线丨暗呦小u女国产精品| 91麻豆国产精品| 亚洲一区二区在线| 韩国三级电影久久久久久| 亚洲欧洲日产国码av系列天堂| 成人性生交大片免费观看嘿嘿视频| 91禁国产网站| 欧美日韩免费观看中文| 欧美性xxxxhd| 日韩高清电影免费观看完整版| 欧美性猛交xxxx免费看| 日韩欧美国产视频| 国产精品99久久久久久久久| 欧美性猛交xxxx乱大交蜜桃| 日韩av第一页| 中文字幕在线日韩| 欧美插天视频在线播放| 欧美夫妻性生活视频| 成人免费淫片aa视频免费| 黑丝美女久久久| 国产女精品视频网站免费| 亚洲第一二三四五区| 美日韩精品免费视频| 精品中文字幕在线2019| 成人久久18免费网站图片| 亚洲人高潮女人毛茸茸| 久久精品国产2020观看福利| 欧美视频在线观看 亚洲欧| 911国产网站尤物在线观看| www.精品av.com| 亚洲欧美在线播放| 97国产在线观看| 国产欧美婷婷中文| 性色av香蕉一区二区| 国产精品91视频| 色综合老司机第九色激情| 久久九九全国免费精品观看| 97超级碰碰碰久久久| 91在线国产电影| 国产精品久久久久久久久久免费| 日韩免费电影在线观看| 亚洲精品欧美极品| 91在线看www| 亚洲r级在线观看| 欧美成人免费全部| 91在线观看欧美日韩| 国产69精品久久久久9| 亚洲人成绝费网站色www| 亚洲国产私拍精品国模在线观看| 亚洲欧洲在线播放| xxxxx成人.com| 国产网站欧美日韩免费精品在线观看| 精品毛片网大全| 日本亚洲欧洲色| 亚洲精品大尺度| 国产精品电影网| 操91在线视频| 国产女精品视频网站免费| 欧美另类在线观看| 久久精品影视伊人网| 精品在线欧美视频| 精品久久久久国产| 日韩欧美精品免费在线| 欧美大奶子在线| 91免费视频网站| 欧美丝袜一区二区| 51色欧美片视频在线观看| 日韩经典第一页| 97超级碰在线看视频免费在线看| 国产一区二区三区精品久久久| 国产亚洲视频中文字幕视频| 欧美在线国产精品| 国产视频精品va久久久久久| 日韩a**站在线观看| 欧美午夜片欧美片在线观看| 亚洲欧美日本精品| 最近2019中文字幕mv免费看| 91九色视频导航| 欧美性受xxxx白人性爽| 日本免费久久高清视频| 亚洲毛片在线观看.| 国产成人精品免高潮在线观看| 一本色道久久综合狠狠躁篇怎么玩| 亚洲在线视频福利| 中文字幕久精品免费视频| 狠狠躁夜夜躁久久躁别揉| 日韩在线视频线视频免费网站| 日韩一区二区三区国产| 欧美另类在线观看| 国产精品久久久久999| 不卡av日日日| 日韩动漫免费观看电视剧高清| 亚洲国产精品va在看黑人|