每日冲刺2
设计语音功能相关代码
<?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" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:orientation="vertical"> <!--标题--> <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar" android:layout_width="match_parent" app:navigationIcon="@mipmap/icon_back" android:layout_height="?attr/actionBarSize" android:background="@color/white"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="手动输入" android:textColor="@color/black" android:textSize="18sp" /> </com.google.android.material.appbar.MaterialToolbar> <!--搜索物品布局--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white"> <RelativeLayout android:layout_width="match_parent" android:layout_height="36dp" android:layout_marginStart="@dimen/sp_16" android:layout_marginTop="@dimen/dp_12" android:layout_marginEnd="@dimen/dp_16" android:layout_marginBottom="@dimen/dp_12" android:background="@drawable/search_et_bg" android:orientation="horizontal"> <ImageView android:id="@+id/iv_search" android:layout_width="@dimen/dp_16" android:layout_height="@dimen/dp_16" android:layout_centerVertical="true" android:layout_marginStart="@dimen/dp_12" android:layout_marginEnd="@dimen/dp_8" app:srcCompat="@mipmap/icon_search" /> <EditText android:id="@+id/et_goods" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_toStartOf="@+id/iv_clear" android:layout_toEndOf="@+id/iv_search" android:background="@null" android:hint="请输入物品" android:imeOptions="actionSearch" android:singleLine="true" android:textColor="@color/black" android:textColorHint="@color/hint_color" android:textCursorDrawable="@drawable/cursor_style" android:textSize="@dimen/sp_14" /> <ImageView android:id="@+id/iv_clear" android:layout_width="@dimen/dp_36" android:layout_height="@dimen/dp_36" android:layout_alignParentEnd="true" android:padding="@dimen/dp_10" android:src="@mipmap/icon_clear" android:visibility="invisible" /> </RelativeLayout> </LinearLayout> <!--列表--> <androidx.recyclerview.widget.RecyclerView android:id="@+id/rv_result" android:layout_width="match_parent" android:layout_height="match_parent" android:overScrollMode="never" android:scrollbars="none" /> </LinearLayout>
package com.llw.goodtrash.contract; import android.annotation.SuppressLint; import com.llw.goodtrash.api.ApiService; import com.llw.goodtrash.model.TrashResponse; import com.llw.mvplibrary.base.BasePresenter; import com.llw.mvplibrary.base.BaseView; import com.llw.mvplibrary.network.NetworkApi; import com.llw.mvplibrary.network.observer.BaseObserver; /** * 手动文字输入页面访问网络 */ public class TextContract { public static class TextPresenter extends BasePresenter<TextView> { /** * 搜索物品 * * @param word 物品名 */ @SuppressLint("CheckResult") public void searchGoods(String word) { ApiService service = NetworkApi.createService(ApiService.class); service.searchGoods(word).compose(NetworkApi.applySchedulers(new BaseObserver<TrashResponse>() { @Override public void onSuccess(TrashResponse groupResponse) { if (getView() != null) { getView().getSearchResponse(groupResponse); } } @Override public void onFailure(Throwable e) { if (getView() != null) { getView().getSearchResponseFailed(e); } } })); } } public interface TextView extends BaseView { /** * 搜索物品返回 * * @param response */ void getSearchResponse(TrashResponse response); /** * 搜索物品异常返回 * * @param throwable */ void getSearchResponseFailed(Throwable throwable); } }
今日尝试语音功能实现
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性