他的实现步骤主要显示最外层一个布局点击搜索框跳转到另一个activity进行逻辑操作
先给出最外层无逻辑的布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="wrap_content"android:id="@+id/fg"tools:context=".view.SouSuo_zdy"><LinearLayoutandroid:orientation="horizontal"android:gravity="center_vertical"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:gravity="center_horizontal"android:orientation="vertical"android:id="@+id/f1_erweima"android:layout_width="60dp"android:layout_height="wrap_content"><ImageViewandroid:id="@+id/image_sao"android:background="#ffffff"android:src="@drawable/sao_hei"android:layout_width="24dp"android:layout_height="20dp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="15sp"android:textColor="#ffffff"android:text="扫啊扫"/></LinearLayout><LinearLayoutandroid:id="@+id/ssk"android:layout_marginLeft="3px"android:layout_marginRight="3px"android:background="@drawable/home_title_bar_search_corner_bg"android:gravity="center_vertical"android:layout_weight="1"android:layout_width="0dp"android:layout_height="40dp"><ImageViewandroid:layout_marginLeft="5dp"android:src="@drawable/a_4"android:layout_width="20dp"android:layout_height="20dp" /><TextViewandroid:id="@+id/sousuo"android:layout_marginLeft="5dp"android:gravity="center_vertical"android:layout_weight="1"android:layout_width="0dp"android:layout_height="30dp"android:textSize="15dp"android:text="运动户外超级品牌类日"/><ImageViewandroid:layout_marginRight="5dp"android:src="@drawable/root"android:layout_width="20dp"android:layout_height="20dp" /></LinearLayout><LinearLayoutandroid:gravity="center_horizontal"android:orientation="vertical"android:layout_width="50dp"android:layout_height="wrap_content"><ImageViewandroid:background="#ffffff"android:src="@drawable/a9v"android:layout_width="20dp"android:layout_height="20dp" /><TextViewandroid:textColor="#ffffff"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="15sp"android:text="消息"/></LinearLayout></LinearLayout>
</FrameLayout>
依赖
implementation 'com.hjm:BottomTabBar:1.1.1' //okhttp implementation 'com.squareup.okhttp3:okhttp:3.5.0' //gson implementation 'com.google.code.gson:gson:2.6.2' //glide implementation 'de.hdodenhof:circleimageview:2.2.0' implementation 'com.github.bumptech.glide:glide:3.7.0' //流式布局 implementation 'com.fynn.fluidlayout:fluidlayout:1.0' implementation 'com.jcodecraeer:xrecyclerview:1.3.2' implementation 'io.reactivex.rxjava2:rxjava:2.0.7' implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' implementation 'com.squareup.retrofit2:retrofit:2.1.0' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0' implementation 'com.squareup.retrofit2:converter-gson:2.1.0' implementation 'com.squareup.retrofit2:converter-scalars:2.1.0' implementation 'com.xhb:xbanner:1.2.2' implementation 'com.github.bumptech.glide:glide:3.7.0' // 一般依赖: implementation 'com.facebook.fresco:fresco:0.14.1' // 如果需要支持gif,再添加: implementation 'com.facebook.fresco:animated-gif:0.12.0' // 在 API < 14 上的机器支持 WebP 时,需要添加 implementation 'com.facebook.fresco:animated-base-support:0.12.0' // 支持 WebP (静态图+动图),需要添加 implementation 'com.facebook.fresco:animated-webp:0.12.0' implementation 'com.facebook.fresco:webpsupport:0.12.0' // 仅支持 WebP 静态图,需要添加 implementation 'com.facebook.fresco:webpsupport:0.12.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.4.2' implementation 'com.youth.banner:banner:1.4.9' implementation 'org.greenrobot:eventbus:3.0.0' implementation files('libs/open_sdk_r5990_lite.jar')implementation 'com.fynn.fluidlayout:fluidlayout:1.0'
activity_sou_suo_zdy
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="wrap_content"android:id="@+id/fg"tools:context=".view.SouSuo_zdy"><LinearLayoutandroid:orientation="horizontal"android:gravity="center_vertical"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:gravity="center_horizontal"android:orientation="vertical"android:id="@+id/f1_erweima"android:layout_width="60dp"android:layout_height="wrap_content"><ImageViewandroid:id="@+id/image_sao"android:background="#ffffff"android:src="@drawable/sao_hei"android:layout_width="24dp"android:layout_height="20dp" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="15sp"android:textColor="#ffffff"android:text="扫啊扫"/></LinearLayout><LinearLayoutandroid:id="@+id/ssk"android:layout_marginLeft="3px"android:layout_marginRight="3px"android:background="@drawable/home_title_bar_search_corner_bg"android:gravity="center_vertical"android:layout_weight="1"android:layout_width="0dp"android:layout_height="40dp"><ImageViewandroid:layout_marginLeft="5dp"android:src="@drawable/a_4"android:layout_width="20dp"android:layout_height="20dp" /><TextViewandroid:id="@+id/sousuo"android:layout_marginLeft="5dp"android:gravity="center_vertical"android:layout_weight="1"android:layout_width="0dp"android:layout_height="30dp"android:textSize="15dp"android:text="运动户外超级品牌类日"/><ImageViewandroid:layout_marginRight="5dp"android:src="@drawable/root"android:layout_width="20dp"android:layout_height="20dp" /></LinearLayout><LinearLayoutandroid:gravity="center_horizontal"android:orientation="vertical"android:layout_width="50dp"android:layout_height="wrap_content"><ImageViewandroid:background="#ffffff"android:src="@drawable/a9v"android:layout_width="20dp"android:layout_height="20dp" /><TextViewandroid:textColor="#ffffff"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="15sp"android:text="消息"/></LinearLayout></LinearLayout>
</FrameLayout>
home_title_bar_search_corner_bg
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><corners android:radius="20dp"/><solid android:color="#F0F2F5" /></shape>
activity_main2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"tools:context=".view.Main2Activity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:paddingTop="10dp"android:gravity="center_vertical"><RadioButtonandroid:id="@+id/bt_quxiao"android:layout_width="52dp"android:layout_height="wrap_content"android:text="取消"android:button="@null"android:textColor="#999999"android:gravity="center"/><RelativeLayoutandroid:layout_width="0dp"android:layout_height="35dp"android:layout_weight="1"><EditTextandroid:id="@+id/search_edit2"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/search_2"android:hint=" 雷士京东超级品牌日, 2件8折"android:textSize="10sp"android:singleLine="true"/><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/search_2"android:layout_alignBottom="@id/search_edit2"android:layout_alignLeft="@id/search_edit2"android:layout_alignTop="@id/search_edit2"android:layout_marginLeft="10dp"/></RelativeLayout><RadioButtonandroid:id="@+id/bt_search"android:layout_width="52dp"android:layout_height="wrap_content"android:text="搜索"android:button="@null"android:textColor="#999999"android:gravity="center"/></LinearLayout><ProgressBarandroid:layout_width="match_parent"android:layout_height="0.5dp"android:background="#cccccc"android:layout_marginTop="5dp"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="热搜"android:textColor="#000"android:layout_margin="10dp"/><com.fynn.fluidlayout.FluidLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/fl"></com.fynn.fluidlayout.FluidLayout><ListViewandroid:id="@+id/search_lv"android:layout_width="match_parent"android:layout_height="wrap_content"></ListView><RadioButtonandroid:id="@+id/rb_clear"android:layout_width="200dp"android:layout_height="40dp"android:layout_gravity="center_horizontal"android:gravity="center"android:button="@null"android:background="@drawable/button_clean"android:textColor="#999999"android:text="清空历史搜索"/></LinearLayout>
search_1
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><!-- android:radius 弧形的半径 --><corners android:radius="50dip" /><!-- padding:Button里面的文字与Button边界的间隔 --><paddingandroid:left="10dp"android:top="10dp"android:right="10dp"android:bottom="10dp"/><!-- 边框的宽度和颜色颜色 --><strokeandroid:width="1px"android:color="#cccccc"/><!-- 背景色 --><solid android:color="#FFF"></solid>
</shape>
search_2
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><!-- android:radius 弧形的半径 --><corners android:radius="50dip" /><!-- padding:Button里面的文字与Button边界的间隔 --><paddingandroid:left="10dp"android:top="10dp"android:right="10dp"android:bottom="10dp"/><!-- 边框的宽度和颜色颜色 --><strokeandroid:width="1px"android:color="#cccccc"/><!-- 背景色 --><solid android:color="#f5f5f5"></solid>
</shape>
button_clean
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><!-- android:radius 弧形的半径 --><corners android:radius="0dip" /><!-- padding:Button里面的文字与Button边界的间隔 --><paddingandroid:left="10dp"android:top="10dp"android:right="10dp"android:bottom="10dp"/><!-- 边框的宽度和颜色颜色 --><strokeandroid:width="1px"android:color="#cccccc"/><!-- 背景色 --><solid android:color="#f5f5f5"></solid>
</shape>
MySql
package com.example.mac.jddome.sql;import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;/*** Created by mac on 2018/4/17.*/public class MySql extends SQLiteOpenHelper {public MySql(Context context){super(context, "search.db", null, 1);}@Overridepublic void onCreate(SQLiteDatabase sqLiteDatabase) {String sql = "create table search(id integer primary key autoincrement,name varchar(20))";sqLiteDatabase.execSQL(sql);}@Overridepublic void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {}
}
MySqlDao
package com.example.mac.jddome.sql;import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;import java.util.ArrayList;
import java.util.List;/*** Created by mac on 2018/4/17.*/public class MySqlDao {private MySql mySQlite;private SQLiteDatabase db;public MySqlDao(Context context){mySQlite = new MySql(context);db = mySQlite.getReadableDatabase();}public void add(String name){ContentValues values = new ContentValues();values.put("name",name);db.insert("search",null,values);}public void delete(String name){db.delete("search","name=?",new String[]{name});}public void deleteAll(){db.execSQL("DELETE FROM search");}public List<String> select(){Cursor cursor = db.rawQuery("select * from search",null);List<String> list = new ArrayList<>();while (cursor.moveToNext()){String name = cursor.getString(cursor.getColumnIndex("name"));list.add(name);}return list;}}
home_title_bar_search_corner_bg
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><corners android:radius="20dp"/><solid android:color="#F0F2F5" /></shape>
主Main
package com.example.administrator.month.view;import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;import com.example.administrator.month.R;public class SouSuo_zdy extends AppCompatActivity implements View.OnClickListener {/*** 运动户外超级品牌类日*/private TextView sousuo;private LinearLayout ssk;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_sou_suo_zdy);initView();}private void initView() {sousuo = (TextView) findViewById(R.id.sousuo);ssk = findViewById(R.id.ssk);sousuo.setOnClickListener(this);ssk.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {default:break;case R.id.ssk:break;case R.id.sousuo:Intent intent = new Intent(SouSuo_zdy.this,Main2Activity.class);startActivity(intent);break;}}
}
下面的代码是点击搜索框跳转到流式布局的搜索页面
package com.example.administrator.month.view;import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;import com.example.administrator.month.R;
import com.example.administrator.month.sqlite.MySqlDao;
import com.fynn.fluidlayout.FluidLayout;import java.util.List;public class Main2Activity extends AppCompatActivity {MySqlDao mySQliteDao;EditText et;FluidLayout fluidLayout;Button bt_quxiao, bt_search;RadioButton rb_clear;ListView lv;List<String> list;MyAdapter myAdapter;String[] arrs = {"倩女幽魂", "单机斗地主", "天堂战记", "妖精的尾巴", "极限挑战", "我们相爱吧", "倚天屠龙记","明星大侦探", "丰乳肥臀", "大主宰", "盗墓笔记", "鬼吹灯", "盘龙", "完美世界", "柠檬初上", "WIFI","锁屏", "异术超能", "东方不败", "巅峰战舰", "小说", "污"};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main2);et = findViewById(R.id.search_edit2);bt_quxiao = findViewById(R.id.bt_quxiao);bt_search = findViewById(R.id.bt_search);rb_clear = findViewById(R.id.rb_clear);fluidLayout = findViewById(R.id.fl);lv = findViewById(R.id.search_lv);
//配置热搜流式布局for (int i = 0; i < arrs.length; i++) {String ss = arrs[i];TextView textView = new TextView(Main2Activity.this);textView.setText(ss);textView.setTextSize(13);textView.setBackgroundColor(Color.parseColor("#f5f5f5"));FluidLayout.LayoutParams params = new FluidLayout.LayoutParams(150, 50);params.setMargins(12, 12, 12, 12);fluidLayout.addView(textView, params);}//查询数据库,配置适配器,显示历史记录listviewmySQliteDao = new MySqlDao(Main2Activity.this);list = mySQliteDao.select();myAdapter = new MyAdapter();lv.setAdapter(myAdapter);//点击事件,返回首页bt_quxiao.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Intent intent = new Intent(Main2Activity.this, SouSuo_zdy.class);startActivity(intent);}});//点击事件,添加搜索内容到数据库bt_search.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {mySQliteDao.add(et.getText().toString());list = mySQliteDao.select();myAdapter.notifyDataSetChanged();Intent intent = new Intent(Main2Activity.this,shop_activity.class);startActivity(intent);}});//点击事件,清空数据库中的搜索内容rb_clear.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {mySQliteDao.deleteAll();list.removeAll(list);myAdapter.notifyDataSetChanged();}});}//显示搜索内容listview的适配器class MyAdapter extends BaseAdapter {@Overridepublic int getCount() {return list.size();}@Overridepublic Object getItem(int i) {return list.get(i);}@Overridepublic long getItemId(int i) {return i;}@Overridepublic View getView(int i, View view, ViewGroup viewGroup) {TextView textView = new TextView(Main2Activity.this);textView.setText(list.get(i));textView.setPadding(15, 15, 15, 15);return textView;}}}
需要用到的图片