做一个简单的天气预报,首先想的就是联网权限,还有对“和风天气” 服务器的HTTP请求
<uses-permission android:name="android.permission.INTERNET" />
先在和风天气(百度搜索)上注册一个账号 并且激活然后登陆,在“官网里”
在控制台里 获取自己的 key
获取JSON数据 的结构
“网址”+”?key”+”自己的秘钥”+”&location=”
接下里我们就需要在xml里 布局了
<?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="com.example.myapplication13.MainActivity">
<EditText
android:hint="请输入城市名称"
android:id="@+id/main_editView"
android:layout_width="match_parent"
android:layout_height="50dp" />
<Button
android:id="@+id/main_button"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="查询" />
<RelativeLayout
andr