前文:

​​​​​​桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 7

导航:

桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 The End 导航页及收尾工作

四、查单词功能的实现。

(1)取消Bottom Navigation Activity模板的顶栏空白。

android:paddingTop="?attr/actionBarSize"

删除即可取消Bottom Navigation Activity模板的顶栏空白。

(2)实现安卓9.0后webview载入网页。

在manifest添加

android:usesCleartextTraffic="true"

即可实现。

(3)以OneFragment为查询单词界面,进行UI布局。

fragment_one.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="#FFFFFF"app:layout_constraintGuide_percent="0.75"><EditTextandroid:id="@+id/editTextTextPersonName3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginStart="16dp"android:ems="12"android:hint="@string/search"android:imeOptions="actionSearch"android:inputType="textPersonName"android:minHeight="48dp"android:singleLine="true"app:layout_constraintEnd_toStartOf="@+id/guideline11"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="@+id/guideline9" /><ImageButtonandroid:id="@+id/imageButton7"android:layout_width="50dp"android:layout_height="50dp"android:backgroundTint="#00FFFFFF"android:contentDescription="@string/TODO"android:src="@drawable/ic_baseline_search_24"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="@+id/guideline11"app:layout_constraintTop_toTopOf="parent" /><androidx.constraintlayout.widget.Guidelineandroid:id="@+id/guideline9"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"app:layout_constraintGuide_percent="0.03" /><androidx.constraintlayout.widget.Guidelineandroid:id="@+id/guideline11"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical"app:layout_constraintGuide_begin="312dp"app:layout_constraintGuide_percent="0.7" /><ImageViewandroid:id="@+id/imageView8"android:layout_width="50dp"android:layout_height="50dp"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.506"app:layout_constraintStart_toStartOf="@+id/guideline11"app:layout_constraintTop_toBottomOf="@+id/imageButton7"app:layout_constraintVertical_bias="0.0"app:srcCompat="@drawable/ic_baseline_close_24" /><WebViewandroid:id="@+id/webview"android:layout_width="409dp"android:layout_height="629dp"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>

需要用到的矢量图:

@drawable/ic_baseline_close_24
@drawable/ic_baseline_search_24

(4) 在Manifest添加权限。(互联网权限)

<uses-permission android:name="android.permission.INTERNET" />

(5)锁定导航栏,防止软键盘将导航栏顶起。

在Manifest的activity里:

即可解决。

(6)编辑OneFragment的代码。

OneFragment.java

package com.example.peachdictionary;import android.os.Bundle;import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;public class OneFragment extends Fragment {@Nullable@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {View view = inflater.inflate(R.layout.fragment_one, container, false);return view;}@Overridepublic void onActivityCreated(@Nullable Bundle savedInstanceState) {super.onActivityCreated(savedInstanceState);WebView webView = getView().findViewById(R.id.webview);ImageButton imageButton7 = getView().findViewById(R.id.imageButton7);imageButton7.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {getdata();}});//软键盘EditText editText = getView().findViewById(R.id.editTextTextPersonName3);editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {@Overridepublic boolean onEditorAction(TextView v, int actionId, KeyEvent event) {if (actionId == EditorInfo.IME_ACTION_SEARCH) {getdata();}return false;}});ImageView imageView8 = getView().findViewById(R.id.imageView8);imageView8.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//链接一张白色图片webView.loadUrl("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage.110go.com%2Fupload%2Ftpk%2F180743034.jpg&refer=http%3A%2F%2Fimage.110go.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642493799&t=0b0f3e6ac47ea94df25b112ff7ea53a6");}});}public void getdata() {EditText editText = getView().findViewById(R.id.editTextTextPersonName3);String str = editText.getText().toString();WebView webView = getView().findViewById(R.id.webview);webView.loadUrl("http://m.youdao.com/dict?le=eng&q="+str);}
}

实现效果:

桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 8相关推荐

  1. 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 4

    前文: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 3 导航: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 The E ...

  2. 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 7

    前文: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 6 导航: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 The E ...

  3. 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 The End 导航页及收尾工作

    导航: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 1 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 2 桃词 ...

  4. 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 1

    前言 由于笔者操作不当,将项目搞崩了,所以打算重写一遍,记下开发过程,作为学习记录.此软件能实现最普通的单词查询功能,也有启动动画.登录注册之类的功能,但笔者目前能力有限,未能将其完善,这是初学阶段的 ...

  5. 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 9

    前文: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 8 导航: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 The E ...

  6. 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 3

    前文: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 2 导航: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 The E ...

  7. 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 5

    前文: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 4 导航: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 The E ...

  8. 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 6

    前文: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 5 导航: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 The E ...

  9. 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 2

    前文:  桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 Part 1 导航: 桃词典 Peach Dictionary 简易英语词典app开发 安卓软件开发 The ...

最新文章

  1. 列名必须是一个字符串或者数组_我爱Julia之入门-078(字符串08)
  2. php 防火墙配置,rhel6+nginx+php+php-fpm 防火墙配置问题
  3. 解封装(二):初始化解封装avformat_open_input,各参数分析,以及简单流程
  4. 如何用vue实现模态框组件
  5. fpga与三八译码器(BASYS3 VIVADO18)
  6. 服务器脱机状态,从脱机工作切换到联机工作
  7. 由swap引出的局部变量,形参和指针的小问题
  8. stylus vue 报错_带你玩转webpack 从零构建Vue工程
  9. Android四大组件(activity task stack)
  10. LabelImg操作手册
  11. 教材推荐 PRML_模式识别与机器学习
  12. linux复制文件到另一个文件夹
  13. 关于CREO图纸导出到CAD后尺寸不对的问题
  14. tags与categories
  15. 介绍identity matrices
  16. 【基于51单片机驱动ST7789VW的TFT显示屏240x240
  17. matlab fisher检验,模式识别中Fisher分类器的Matlab实现及测试
  18. sharding-jdbc系列之常见问题(十四)
  19. 基于springboot的在线商城管理系统
  20. Web(万维网)发展简史

热门文章

  1. Mac上显示实时网速小工具
  2. DirectX11 骷髅头示例Demo
  3. 微信公众平台开发——引言
  4. UE4粒子在镜头看不到时不显示问题解决
  5. 烂笔头 | OpenMMLab 第一讲
  6. 六问禅道5:需求和Bug的区别
  7. 前端iframe标签介绍及使用
  8. 中国大学慕课第六周编程题
  9. arcgis制作瓦片地图_一种GIS瓦片地图的存储方式的制作方法
  10. 计算机编程英语单词多少,计算机编程常用英语单词