实现效果图

     

(1)新建text.xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" ><RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:background="@mipmap/main_title_bg"
        ><EditText
          android:layout_width="300dp"
          android:layout_height="40dp"
          android:layout_marginLeft="20dp"
          android:layout_centerVertical="true"
          android:background="@mipmap/et_contact_bg"
          android:hint="请输入课程名称"
          android:textSize="15sp"
          /><ImageView
            android:id="@+id/iv_no"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@mipmap/course_message_no"
            android:layout_alignParentRight="true"
            android:layout_marginTop="5dp"
            android:layout_marginRight="10dp"/><TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="消息"
            android:textColor="#fff"
            android:textSize="13sp"
            android:layout_marginRight="10dp"
            android:layout_below="@+id/iv_no"
            android:layout_alignParentRight="true"
            /></RelativeLayout><LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fbfbfb"
        android:orientation="horizontal" ><ListView
            android:id="@+id/listview_ss"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:scrollbars="none"
            android:layout_weight="1.0"
            android:background="#f4f4f4" /><View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#cdcdcd" /><FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3.0" /></LinearLayout></LinearLayout>

(2)新建TestActivity.java文件

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
public class TestActivity extends FragmentActivity implements AdapterView.OnItemClickListener {private String[] strs = { "全部课程", "拼音", "同步+奥数", "新概念英语", "晚托班", "音标", "暑托班","围棋", "美术","硬笔书法", "毛笔书法", "幼小衔接班", "小升初", "英语一对一", "语文", "数学","英语" };private ListView listView;private MyAdapter adapter;private MyFragment myFragment;public static int mPosition;@Override
    protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.test);initView();}/**
     * 初始化view
     */
    private void initView() {// TODO Auto-generated method stub
        listView = (ListView) findViewById(R.id.listview);adapter = new MyAdapter(this, strs);listView.setAdapter(adapter);listView.setOnItemClickListener(this);//创建MyFragment对象
        myFragment = new MyFragment();FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();fragmentTransaction.replace(R.id.fragment_container, myFragment);//通过bundle传值给MyFragment
        Bundle bundle = new Bundle();bundle.putString(MyFragment.TAG, strs[mPosition]);myFragment.setArguments(bundle);fragmentTransaction.commit();}@Override
    public void onItemClick(AdapterView<?> parent, View view, int position,long id) {// TODO Auto-generated method stub
        //拿到当前位置
        mPosition = position;//即使刷新adapter
        adapter.notifyDataSetChanged();for (int i = 0; i < strs.length; i++) {myFragment = new MyFragment();FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();fragmentTransaction.replace(R.id.fragment_container, myFragment);Bundle bundle = new Bundle();bundle.putString(MyFragment.TAG, strs[position]);myFragment.setArguments(bundle);fragmentTransaction.commit();}}
}
(3)新建MyFragment文件
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
 * Created by Administrator on 2018/4/26.
 */
public class MyFragment extends Fragment {public static final String TAG = "MyFragment";private String str;@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.myfragment, null);
//TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
//得到数据
str = getArguments().getString(TAG);
Toast.makeText(getActivity(), "未找到相关课程哦", Toast.LENGTH_SHORT).show();
//tv_title.setText(str);
return view;
  }
 }

(4)新建MyAdapter文件

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
 * Created by Administrator on 2018/4/26.
 */
public class MyAdapter extends BaseAdapter {private Context context;private String[] strings;public static int mPositionpublic MyAdapter(Context context, String[] strings){this.context =context;this.strings = strings;}@Override
    public int getCount() {// TODO Auto-generated method stub
        return strings.length;}@Override
    public Object getItem(int position) {// TODO Auto-generated method stub
        return strings[position];}@Override
    public long getItemId(int position) {// TODO Auto-generated method stub
        return position;}@Override
    public View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stub
        convertView = LayoutInflater.from(context).inflate(R.layout.listview_item, null);TextView tv = (TextView) convertView.findViewById(R.id.tv);mPosition = position;tv.setText(strings[position]);if (position == TestActivity.mPosition) {convertView.setBackgroundResource(R.mipmap.checkline);} else {convertView.setBackgroundColor(Color.parseColor("#ADADAD"));}return convertView;}
}

(5)新建listview_item.xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"><TextView
        android:id="@+id/tv"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:gravity="center"
        android:text="Button2" />
</LinearLayout>
(6)新建myfragment.xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"><TextView
    android:id="@+id/tv_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button" />
</LinearLayout>

ListView+Fragment实现导航栏相关推荐

  1. Fragment底部导航栏的实现

    1.要实现的效果图以及工程目录结构: 先看看效果图吧: 接着看看我们的工程的目录结构: 2.实现流程: Step 1:写下底部选项的一些资源文件 我们从图上可以看到,我们底部的每一项点击的时候都有不同 ...

  2. BottomNavigationView+ViewPager+Fragment仿微信底部导航栏

    目标: 要实现的界面如下: 此时,我们需要采用BottomNavigationView+ViewPager+Fragment,一点点的说起.首先要在app/build.gradle里添加: imple ...

  3. Android studio实现底部导航,AndroidStudio制作底部导航栏以及用Fragment实现切换功能...

    前言 大家好,我是 Vic,今天给大家带来AndroidStudio制作底部导航栏以及用Fragment实现切换功能的概述,希望你们喜欢 学习目标 AndroidStudio制作底部导航栏以及用Fra ...

  4. android fragment 底部菜单栏,一句话搞定Android底部导航栏,一键绑定Fragment、ViewPager...

    现在大多数App都会用到底部导航栏,比如常见的聊天工具QQ.微信.购物App等等,有了底部导航栏,用户可以随时切换界面,查看不同的内容.它的实现方式也很多,以前大多使用TabHost来实现,但是现在我 ...

  5. android radiobutton底部导航,android中Fragment+RadioButton实现底部导航栏

    在App中经常看到这样的tab底部导航栏 那么这种效果是如何实现,实现的方式有很多种,最常见的就是使用Fragment+RadioButton去实现.下面我们来写一个例子 首先我们先在activity ...

  6. Android肝帝战纪之基于上篇单Activity+多Fragment框架,开发电商式导航栏,多Fragment切换

    电商式导航栏,多Fragment切换 本文默认在已经搭建好的框架上进行开发 点此链接到上一篇基础框架的搭建 界面构思示意图 设计思路 在底部的LinearLayout中添加相应的图标,然后设置tag绑 ...

  7. php点击切换图片的底部导航,如何优雅地使用BottomNavigationView实现底部导航栏+fragment切换效果...

    BottomNavigationView.jpeg 引言 之前总是使用RadioButton+ViewPager来实现底部导航栏+fragment切换效果,总是繁琐地还需要写ViewPager的适配器 ...

  8. android listview 导航条,Android侧边导航栏+ListView基础实践

    Android基础项目实践 文章首发于自己的github博客,https://lemonjuice98.github.io/ 本学期学习了Android的开发课程,期末也做了一款很萌新向的App作为课 ...

  9. 安卓项目实践——仿淘宝界面(二)——底部导航栏技术(Fragment实现)

    安卓项目实践--仿淘宝界面(一)--底部导航栏技术(Fragment实现) 1.实现效果展示 2.技术简述 该导航栏主要使用Fragment技术实现,关于Fragment的介绍大家可以自行百度,导航栏 ...

最新文章

  1. 国内IT出版社的四大软肋
  2. Centos7 安装maven3.5.0和git
  3. c#书写规范之---注释
  4. Kotlin学习 PART 3:类,对象和接口
  5. 三、糖醋鲤鱼(Sweet and sour carp)
  6. vuepress侧边栏配置_VuePress搭建静态博客网站
  7. Win10+vs2013+Caffe静态库配置自己的工程
  8. vue-resource jsonp跨域问题解决方法
  9. Java中static变量作用和用法详解
  10. 剑指offer——6.从尾到头打印链表
  11. oracle和mysql数据实时同步_FileYee文件实时同步备份软件,再不怕数据丢失
  12. ROI与CPC、CPM有什么关系
  13. PNG转ICO在线转换
  14. iPhone加码“独立王国” 有可能成摆设?
  15. 最新全国手机号码归属地信息SQLite数据库2019年2月更新
  16. 如鹏java学习进程 将输入的正整数相加,ok结尾
  17. SNAP7 PLC协议S7 PDU程式读取长度
  18. 宇宙最强,meltdown论文中英文对照版(三)
  19. Oracle 10G 64位下载
  20. 制作一个浪漫的表白网页

热门文章

  1. 网络工程项目报价单应该怎么写?记住这6个步骤准没错!
  2. 百度地图API入门1-申请百度API key
  3. 大数据工程师入职京东年薪37w(附:面试真题分享)
  4. 走到哪里都有我们的精彩
  5. 7周入门数据分析:(2)分析界的No.1——Excel
  6. 著名的菲波拉契(Fibonacci)数列,其第一项为0,第二项为1,从第三项开始,其每一项都是前两项的和。编程求出该数列前N项数据。
  7. 胆囊结石的危害你了解多少?
  8. 基于simulink的风力机房温度控制系统仿真
  9. 2021csgo网页开箱网站有哪些?csgo靠谱的开箱网站大全
  10. 开源项目分析解读——基于Spring Cloud的在线考试系统