Android 蓝牙开发(扫描设备、绑定、解绑)(1)

android:layout_height=“wrap_content”

android:layout_gravity=“center”

android:text=“我的蓝牙”

android:textColor=“#000”

android:textSize=“18sp” />

</androidx.appcompat.widget.Toolbar>

<View

android:layout_width=“match_parent”

android:layout_height=“1dp”

android:background=“#EEEEEE” />

<LinearLayout

android:id=“@+id/loading_lay”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:gravity=“center”

android:visibility=“gone”>

<ProgressBar

android:layout_width=“@dimen/dp_40”

android:layout_height=“@dimen/dp_40”

android:indeterminate=“true”

android:indeterminateDrawable=“@drawable/progressbar” />

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“扫描中…” />

<androidx.recyclerview.widget.RecyclerView

android:id=“@+id/rv”

android:background=“#FFF”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“1” />

<View

android:layout_width=“match_parent”

android:layout_height=“1dp”

android:background=“#EEEEEE” />

<TextView

android:id=“@+id/scan_devices”

android:layout_width=“match_parent”

android:layout_height=“50dp”

android:background=“?android:attr/selectableItemBackground”

android:gravity=“center”

android:text=“扫描蓝牙” />

在layout下创建列表展示的item的布局文件,名为item_device_list.xml

在这里插入图片描述

代码如下:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:orientation=“vertical”

android:id=“@+id/item_device”

android:background=“?android:attr/selectableItemBackground”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”>

<LinearLayout

android:gravity=“center_vertical”

android:padding=“12dp”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”>

<ImageView

android:id=“@+id/iv_device_type”

android:src=“@mipmap/icon_bluetooth”

android:layout_width=“30dp”

android:layout_height=“30dp”/>

<TextView

android:id=“@+id/tv_name”

android:paddingLeft=“12dp”

android:textSize=“16sp”

android:text=“设备名称”

android:textColor=“#000”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<TextView

android:gravity=“right”

android:id=“@+id/tv_bond_state”

android:text=“绑定状态”

android:layout_width=“0dp”

android:layout_weight=“1”

android:layout_height=“wrap_content”/>

<View

android:background=“#EBEBEB”

android:layout_marginLeft=“54dp”

android:layout_width=“match_parent”

android:layout_height=“1dp”/>

三、编码


在此之前呢,记得放一个工具类,用于改变状态栏的文字和背景颜色的。创建一个util包,包下创建一个StatusBarUtil.java文件

在这里插入图片描述

工具类代码如下:

package com.llw.mybluetooth.util;

import android.annotation.TargetApi;

import android.app.Activity;

import android.graphics.Color;

import android.os.Build;

import android.view.View;

import android.view.Window;

import android.view.WindowManager;

import java.lang.reflect.Field;

import java.lang.reflect.Method;

/**

  • 状态栏工具类

*/

public class StatusBarUtil {

/**

  • 修改状态栏为全透明

  • @param activity

*/

@TargetApi(19)

public static void transparencyBar(Activity activity) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

Window window = activity.ge

  • 16
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值