以华为p10手机为例, *** 如下:
1、长按手机桌面空白的地方,如下图。
2、点击下面窗口的天气选项,如下图。
3、在下面选择窗口小工具,如下图。
4、选择想要设置的一个款式。
5、移动到桌面空白处,如下图。
6、这样就设置成功了,如下图。
本经验将介绍Android如何获取天气预报主要使用了中国天气网的接口,使用webView显示。
工具/原料
Android Studio
*** /步骤
首先我们打开下载安装好的Android Studio然后新建一个项目,我这里为了方便就直接添加一个Activity了
然后我们添加界面布局代码,布局如下:
?xml version="1.0" encoding="utf-8"?
LinearLayout xmlns:android=""
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Button
android:id="@+id/bj"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bj" /
Button
android:id="@+id/sh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sh" /
Button
android:id="@+id/heb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heb" /
Button
android:id="@+id/cc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cc" /
Button
android:id="@+id/sy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sy" /
Button
android:id="@+id/gz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gz" /
/LinearLayout
WebView android:id="@+id/webView1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:focusable="false"
android:layout_weight="1"
/
/LinearLayout
然后我们添加后台代码:
package com.basillee.asus.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
public class MainActivity7 extends Activity implements OnClickListener {
private WebView webView; //声明WebView组件的对象
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity7);
webView=(WebView)findViewById(R.id.webView1); //获取WebView组件
webView.getSettings().setJavaScriptEnabled(true); //设置JavaScript可用
webView.setWebChromeClient(new WebChromeClient()); //处理JavaScript对话框
webView.setWebViewClient(new WebViewClient()); //处理各种通知和请求事件,如果不使用该句代码,将使用内置浏览器访问网页
webView.loadUrl(" "); //设置默认显示的天气预报信息
webView.setInitialScale(57*4); //放网页内容放大4倍
Button bj=(Button)findViewById(R.id.bj); //获取布局管理器中添加的“北京”按钮
bj.setOnClickListener(this);
Button sh=(Button)findViewById(R.id.sh); //获取布局管理器中添加的“上海”按钮
sh.setOnClickListener(this);
Button heb=(Button)findViewById(R.id.heb); //获取布局管理器中添加的“哈尔滨”按钮
heb.setOnClickListener(this);
Button cc=(Button)findViewById(R.id.cc); //获取布局管理器中添加的“长春”按钮
cc.setOnClickListener(this);
Button sy=(Button)findViewById(R.id.sy); //获取布局管理器中添加的“沈阳”按钮
sy.setOnClickListener(this);
Button gz=(Button)findViewById(R.id.gz); //获取布局管理器中添加的“广州”按钮
gz.setOnClickListener(this);
}
@Override
public void onClick(View view){
switch(view.getId()){
case R.id.bj: //单击的是“北京”按钮
openUrl("101010100T");
break;
case R.id.sh: //单击的是“上海”按钮
openUrl("101020100T");
break;
case R.id.heb: //单击的是“哈尔滨”按钮
openUrl("101050101T");
break;
case R.id.cc: //单击的是“长春”按钮
openUrl("101060101T");
break;
case R.id.sy: //单击的是“沈阳”按钮
openUrl("101070101T");
break;
case R.id.gz: //单击的是“广州”按钮
openUrl("101280101T");
break;
}
}
//打开网页的 ***
private void openUrl(String id){
webView.loadUrl(""+id+" "); //获取并显示天气预报信息
}
}
然后我们点击Android Studio上面的运行按钮:
这里要访问 *** 我们要添加权限:
uses-permission android:name="android.permission.INTERNET" /
6
我们然后可以在模拟器上面可以看到获取的天气情况
如果您使用的是华为手机,可以通过以下操作添加天气、时钟等桌面小工具。
1、在桌面上双指捏合,进入桌面编辑状态。
2、点击窗口小工具,然后可以向左滑动查看所有小工具。
3、部分小工具(如天气)会有多种样式,点击该图标可以展开所有的样式。向右滑动展开的样式,可以收拢。
4、点击需要的小工具图标,即可将其添加到当前屏幕。如果当前屏幕没有空间,您可以长按并拖动该图标,将其添加到其它屏幕。
由于自称为 Lapsus$ 的组织泄露了与英伟达黑客攻击相关的数据,被盗的代码签名证书被用于远程访问未受保护的 PC,其他情况下则被用来部署恶意软件。 根据 Techpowerup 的报道,这些证书被用于“开发一种新型恶意软件”,BleepingComputer 将 Cobalt Strike...
尽管发布了一个更新来解决macOS Monterey中的两个零日漏洞,但苹果还没有将其应用于最后两个macOS版本,这可能会让多达40%正在使用的Mac计算机处于危险之中。 苹果在2022年3月31日对macOS Monterey的更新中解决了这些关键的漏洞。然而,到目前为止,它还没有更新macO...
就在我们了解到国家支持的黑客已经开始研究上周震惊网络安全界的Log4j漏洞问题时,其他研究人员发出了一个令人不安的发展信号。Log4j黑客,也被称为Log4Shell已经有一个补丁,已经可以部署到企业。但事实证明,这个补丁玩起了“套娃”:它解决原有问题的同时又产生新的安全问题,且可以被外部利用。因此...
时间已正式迈入 2022 年,分析公司 Chainalysis 表示在过去一年中与加密货币有关的犯罪达到了历史最高水平,非法地址获得了惊人的 140 亿美元。收到的绝大部分资金是通过诈骗、盗窃和暗网市场获得的,而另一个不断增长的被盗资金来源则是赎金。 非法资金从 2020 年的 78 亿美...
在 ESET 和微软研究人员的帮助下,乌克兰官员表示成功阻止了一起针对能源设施的网络攻击。在本次阻止攻击过程中,它们发现了 Industroyer 的新变种,它是一个臭名昭著的恶意软件,在 2016 年被 Sandworm APT 组织用来切断乌克兰的电力。 乌克兰政府计算机应急小组(CERT-U...
Nord Locker 安全分析师发现,在 2018-2020 年间黑客利用一个木马化恶意程序,感染了超过 300 多万台电脑,并从中攫取了 1.2T 以上的敏感信息。这款尚未命名的恶意软件从超过 325 万台 Windows PC 中收集信息,收集的数据包括 20 亿个 cookies 和 110...