最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android簡單實(shí)現(xiàn)天氣預(yù)報App

 更新時間:2022年09月11日 12:10:44   作者:啦啦啦???  
這篇文章主要為大家詳細(xì)介紹了Android簡單實(shí)現(xiàn)天氣預(yù)報App,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android簡單實(shí)現(xiàn)天氣預(yù)報App的具體代碼,供大家參考,具體內(nèi)容如下

一、UI設(shè)計

首頁UI

<?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="@drawable/week10_3"
? ? tools:context=".MainActivity">

? ? <TextView
? ? ? ? android:id="@+id/text1"
? ? ? ? android:layout_width="133dp"
? ? ? ? android:layout_height="81dp"
? ? ? ? android:text="確定"
? ? ? ? android:textSize="30dp"
? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? android:gravity="center"
? ? ? ? app:layout_constraintBottom_toBottomOf="parent"
? ? ? ? app:layout_constraintLeft_toLeftOf="parent"
? ? ? ? app:layout_constraintRight_toRightOf="parent"
? ? ? ? app:layout_constraintTop_toTopOf="parent" />

? ? <EditText
? ? ? ? android:id="@+id/address"
? ? ? ? android:layout_width="214dp"
? ? ? ? android:layout_height="98dp"
? ? ? ? android:layout_marginTop="180dp"
? ? ? ? android:ems="10"
? ? ? ? android:inputType="textPersonName"
? ? ? ? android:text="請選擇城市"
? ? ? ? android:gravity="center"
? ? ? ? android:textSize="30dp"
? ? ? ? app:layout_constraintEnd_toEndOf="parent"
? ? ? ? app:layout_constraintHorizontal_bias="0.497"
? ? ? ? app:layout_constraintStart_toStartOf="parent"
? ? ? ? app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

效果:

展示頁面UI

<?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="@drawable/view"
? ? tools:context=".ShowActivity">


? ? <TextView
? ? ? ? android:id="@+id/textView"
? ? ? ? android:layout_width="107dp"
? ? ? ? android:layout_height="59dp"
? ? ? ? android:layout_marginStart="16dp"
? ? ? ? android:layout_marginTop="36dp"
? ? ? ? android:gravity="center"
? ? ? ? android:text="地址"
? ? ? ? android:textColor="@color/white"
? ? ? ? android:textSize="30dp"
? ? ? ? app:layout_constraintStart_toStartOf="parent"
? ? ? ? app:layout_constraintTop_toTopOf="parent" />

? ? <TextView
? ? ? ? android:id="@+id/textView3"
? ? ? ? android:layout_width="153dp"
? ? ? ? android:layout_height="142dp"
? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? android:gravity="center"
? ? ? ? android:text="氣溫"
? ? ? ? android:textColor="@color/white"
? ? ? ? android:textSize="70dp"
? ? ? ? app:layout_constraintStart_toStartOf="@+id/textView"
? ? ? ? app:layout_constraintTop_toBottomOf="@+id/textView" />

? ? <TextView
? ? ? ? android:id="@+id/textView4"
? ? ? ? android:layout_width="98dp"
? ? ? ? android:layout_height="55dp"
? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? android:gravity="center"
? ? ? ? android:text="天氣"
? ? ? ? android:textColor="@color/white"
? ? ? ? android:textSize="30dp"
? ? ? ? app:layout_constraintBottom_toBottomOf="@+id/textView3"
? ? ? ? app:layout_constraintStart_toEndOf="@+id/textView3" />

? ? <TextView
? ? ? ? android:id="@+id/textView5"
? ? ? ? android:layout_width="251dp"
? ? ? ? android:layout_height="60dp"
? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? android:gravity="left"
? ? ? ? android:text="風(fēng)力風(fēng)向 濕度"
? ? ? ? android:textColor="@color/white"
? ? ? ? android:textSize="23dp"

? ? ? ? app:layout_constraintStart_toStartOf="@+id/textView3"
? ? ? ? app:layout_constraintTop_toBottomOf="@+id/textView3" />

? ? <TextView
? ? ? ? android:id="@+id/textView6"
? ? ? ? android:layout_width="97dp"
? ? ? ? android:layout_height="44dp"
? ? ? ? android:text="空氣質(zhì)量"
? ? ? ? android:textColor="@color/white"
? ? ? ? android:gravity="center"
? ? ? ? android:textSize="20dp"
? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? app:layout_constraintBottom_toTopOf="@+id/textView4"
? ? ? ? app:layout_constraintEnd_toEndOf="parent" />

? ? <androidx.constraintlayout.widget.ConstraintLayout
? ? ? ? android:layout_width="185dp"
? ? ? ? android:layout_height="190dp"
? ? ? ? app:layout_constraintBottom_toBottomOf="parent"
? ? ? ? app:layout_constraintStart_toStartOf="parent">

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/texttoday"
? ? ? ? ? ? android:layout_width="70dp"
? ? ? ? ? ? android:layout_height="45dp"
? ? ? ? ? ? android:layout_marginStart="8dp"
? ? ? ? ? ? android:layout_marginTop="20dp"
? ? ? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? ? ? android:gravity="center"
? ? ? ? ? ? android:text="今天"
? ? ? ? ? ? android:textColor="@color/white"
? ? ? ? ? ? android:textSize="24dp"
? ? ? ? ? ? app:layout_constraintStart_toStartOf="parent"
? ? ? ? ? ? app:layout_constraintTop_toTopOf="parent" />

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/weathertoday"
? ? ? ? ? ? android:layout_width="100dp"
? ? ? ? ? ? android:layout_height="45dp"
? ? ? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? ? ? android:gravity="center"
? ? ? ? ? ? android:text="TextView"
? ? ? ? ? ? android:textColor="@color/white"
? ? ? ? ? ? android:textSize="24dp"
? ? ? ? ? ? app:layout_constraintEnd_toEndOf="parent"
? ? ? ? ? ? app:layout_constraintTop_toTopOf="@+id/texttoday" />

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/temtoday"
? ? ? ? ? ? android:layout_width="100dp"
? ? ? ? ? ? android:layout_height="45dp"
? ? ? ? ? ? android:layout_marginTop="30dp"
? ? ? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? ? ? android:gravity="left"
? ? ? ? ? ? android:text="TextView"
? ? ? ? ? ? android:textColor="@color/white"
? ? ? ? ? ? android:textSize="24dp"
? ? ? ? ? ? app:layout_constraintStart_toStartOf="@+id/texttoday"
? ? ? ? ? ? app:layout_constraintTop_toBottomOf="@+id/texttoday" />

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/qualtoday"
? ? ? ? ? ? android:layout_width="50dp"
? ? ? ? ? ? android:layout_height="45dp"
? ? ? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? ? ? android:gravity="left"
? ? ? ? ? ? android:text="良"
? ? ? ? ? ? android:textColor="@color/white"
? ? ? ? ? ? android:textSize="24dp"
? ? ? ? ? ? app:layout_constraintEnd_toEndOf="parent"
? ? ? ? ? ? app:layout_constraintTop_toTopOf="@+id/temtoday" />

? ? </androidx.constraintlayout.widget.ConstraintLayout>

? ? <androidx.constraintlayout.widget.ConstraintLayout
? ? ? ? android:layout_width="185dp"
? ? ? ? android:layout_height="190dp"
? ? ? ? app:layout_constraintBottom_toBottomOf="parent"
? ? ? ? app:layout_constraintEnd_toEndOf="parent">

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/texttomo"
? ? ? ? ? ? android:layout_width="70dp"
? ? ? ? ? ? android:layout_height="45dp"
? ? ? ? ? ? android:layout_marginStart="8dp"
? ? ? ? ? ? android:layout_marginTop="20dp"
? ? ? ? ? ? android:text="明天"
? ? ? ? ? ? android:textSize="24dp"
? ? ? ? ? ? android:textColor="@color/white"
? ? ? ? ? ? android:gravity="center"
? ? ? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? ? ? app:layout_constraintStart_toStartOf="parent"
? ? ? ? ? ? app:layout_constraintTop_toTopOf="parent" />

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/weathertomo"
? ? ? ? ? ? android:layout_width="100dp"
? ? ? ? ? ? android:layout_height="45dp"
? ? ? ? ? ? android:layout_marginEnd="15dp"
? ? ? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? ? ? android:gravity="center"
? ? ? ? ? ? android:text="TextView"
? ? ? ? ? ? android:textColor="@color/white"
? ? ? ? ? ? android:textSize="24dp"
? ? ? ? ? ? app:layout_constraintEnd_toEndOf="parent"
? ? ? ? ? ? app:layout_constraintTop_toTopOf="@+id/texttomo" />

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/temtomo"
? ? ? ? ? ? android:layout_width="100dp"
? ? ? ? ? ? android:layout_height="45dp"
? ? ? ? ? ? android:layout_marginTop="30dp"
? ? ? ? ? ? android:text="TextView"
? ? ? ? ? ? android:textSize="24dp"
? ? ? ? ? ? android:textColor="@color/white"
? ? ? ? ? ? android:gravity="center"
? ? ? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? ? ? app:layout_constraintStart_toStartOf="@+id/texttomo"
? ? ? ? ? ? app:layout_constraintTop_toBottomOf="@+id/texttomo" />

? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/qualtomo"
? ? ? ? ? ? android:layout_width="50dp"
? ? ? ? ? ? android:layout_height="45dp"
? ? ? ? ? ? android:text="TextView"
? ? ? ? ? ? android:textSize="24dp"
? ? ? ? ? ? android:textColor="@color/white"
? ? ? ? ? ? android:gravity="center"
? ? ? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? ? ? app:layout_constraintEnd_toEndOf="@+id/weathertomo"
? ? ? ? ? ? app:layout_constraintTop_toTopOf="@+id/temtomo" />
? ? </androidx.constraintlayout.widget.ConstraintLayout>

? ? <TextView
? ? ? ? android:id="@+id/textView16"
? ? ? ? android:layout_width="251dp"
? ? ? ? android:layout_height="60dp"
? ? ? ? android:fontFamily="sans-serif-black"
? ? ? ? android:gravity="left"
? ? ? ? android:text="TextView"
? ? ? ? android:textColor="@color/white"
? ? ? ? android:textSize="23dp"
? ? ? ? app:layout_constraintStart_toStartOf="@+id/textView3"
? ? ? ? app:layout_constraintTop_toBottomOf="@+id/textView5" />
</androidx.constraintlayout.widget.ConstraintLayout>

效果:

二、調(diào)用數(shù)據(jù)并上傳至前臺

這里我將首頁設(shè)置一個輸入框,里面輸入地點(diǎn),然后將地點(diǎn)的值傳給展示頁面,讓展示頁面接收到地點(diǎn)后再連接對應(yīng)的API并調(diào)用數(shù)據(jù)。

1.首頁

代碼如下(示例):

@Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? getSupportActionBar().hide();
? ? ? ? ImmersionBar.with(this)
? ? ? ? ? ? ? ? //.statusBarColor(R.color.purple_200) ? ? //不寫默認(rèn)透明
? ? ? ? ? ? ? ? .init();

? ? ? ? TextView textView=findViewById(R.id.text1);
? ? ? ? EditText editText=findViewById(R.id.address);

? ? ? ? textView.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View view) {
? ? ? ? ? ? ? ? String address=editText.getText().toString();
? ? ? ? ? ? ? ? Intent intent=new Intent(MainActivity.this,ShowActivity.class);
? ? ? ? ? ? ? ? intent.putExtra("address",address);
? ? ? ? ? ? ? ? startActivity(intent);

? ? ? ? ? ? }
? ? ? ? });
? ? ? ? editText.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View view) {
? ? ? ? ? ? ? ? if(editText.getText().toString()!=null){
? ? ? ? ? ? ? ? ? ? editText.setText("");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? });


? ? }

2.展示頁面

代碼如下(示例):

@Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_show);
? ? ? ? getSupportActionBar().hide();
? ? ? ? ImmersionBar.with(this)
? ? ? ? ? ? ? ? //.statusBarColor(R.color.purple_200) ? ? //不寫默認(rèn)透明
? ? ? ? ? ? ? ? .init();

? ? ? ? TextView textView=findViewById(R.id.textView);
? ? ? ? TextView tem=findViewById(R.id.textView3);
? ? ? ? TextView wind=findViewById(R.id.textView5);
? ? ? ? TextView aqi=findViewById(R.id.textView6);
? ? ? ? TextView weather=findViewById(R.id.textView4);
? ? ? ? TextView ziwaixian=findViewById(R.id.textView16);

? ? ? ? TextView t2=findViewById(R.id.weathertoday);
? ? ? ? TextView t3=findViewById(R.id.temtoday);
? ? ? ? TextView t4=findViewById(R.id.qualtoday);

? ? ? ? TextView m2=findViewById(R.id.weathertomo);
? ? ? ? TextView m3=findViewById(R.id.temtomo);
? ? ? ? TextView m4=findViewById(R.id.qualtomo);

? ? ? ? Intent intent=getIntent();
? ? ? ? String address=getIntent().getStringExtra("address");
? ? ? ? textView.setText(address);

? ? ? ? //c5494be085dd41dca6ec4ffa59c9ed6a
? ? ? ? String code="APPCODE "+"c5494be085dd41dca6ec4ffa59c9ed6a";
? ? ? ? Api api=RetrofitUtils.getRetrofit("https://ali-weather.showapi.com/").create(Api.class);
? ? ? ? Call<WeatherResult> weatherResultCall=api.getWeather(code,address);
? ? ? ? weatherResultCall.enqueue(new Callback<WeatherResult>() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onResponse(Call<WeatherResult> call, Response<WeatherResult> response) {
? ? ? ? ? ? ? ? WeatherResult weatherResult = response.body();

? ? ? ? ? ? ? ? t2.setText(weatherResult.showapi_res_body.f1.day_weather);
? ? ? ? ? ? ? ? t3.setText(weatherResult.showapi_res_body.f1.day_air_temperature+"/"+weatherResult.showapi_res_body.f1.night_air_temperature+"℃");
? ? ? ? ? ? ? ? t4.setText(weatherResult.showapi_res_body.f1.jiangshui);

? ? ? ? ? ? ? ? m2.setText(weatherResult.showapi_res_body.f2.day_weather);
? ? ? ? ? ? ? ? m3.setText(weatherResult.showapi_res_body.f2.day_air_temperature+"/"+weatherResult.showapi_res_body.f2.night_air_temperature+"℃");
? ? ? ? ? ? ? ? m4.setText(weatherResult.showapi_res_body.f2.jiangshui);

? ? ? ? ? ? ? ? tem.setText(weatherResult.showapi_res_body.now.temperature+"℃");
? ? ? ? ? ? ? ? weather.setText(weatherResult.showapi_res_body.now.weather);
? ? ? ? ? ? ? ? wind.setText(weatherResult.showapi_res_body.now.wind_direction+weatherResult.showapi_res_body.now.wind_power+" "+weatherResult.showapi_res_body.now.sd);
? ? ? ? ? ? ? ? aqi.setText("aqi:"+weatherResult.showapi_res_body.now.aqi);
? ? ? ? ? ? ? ? ziwaixian.setText("紫外線強(qiáng)度:"+weatherResult.showapi_res_body.f1.ziwaixian);

? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onFailure(Call<WeatherResult> call, Throwable t) {

? ? ? ? ? ? }
? ? ? ? });
? ? }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android的簡單前后端交互(okHttp+springboot+mysql)

    Android的簡單前后端交互(okHttp+springboot+mysql)

    這篇文章主要介紹了Android的簡單前后端交互(okHttp+springboot+mysql),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • Android短信接收監(jiān)聽、自動回復(fù)短信操作例子

    Android短信接收監(jiān)聽、自動回復(fù)短信操作例子

    本文實(shí)現(xiàn)了短信接收監(jiān)聽,當(dāng)接收到短信時,可自動回復(fù)短信,或自動回?fù)茈娫?,同時監(jiān)聽短信的發(fā)送狀態(tài)
    2014-04-04
  • Android 畫中畫模式的實(shí)現(xiàn)示例

    Android 畫中畫模式的實(shí)現(xiàn)示例

    這篇文章主要介紹了Android 畫中畫模式的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Android實(shí)現(xiàn)app應(yīng)用多語言切換功能

    Android實(shí)現(xiàn)app應(yīng)用多語言切換功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)app應(yīng)用多語言切換功能的相關(guān)資料,類似于微信的語言切換,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android中一個應(yīng)用實(shí)現(xiàn)多個圖標(biāo)的幾種方式

    Android中一個應(yīng)用實(shí)現(xiàn)多個圖標(biāo)的幾種方式

    這篇文章主要給大家介紹了在Android中一個應(yīng)用如何實(shí)現(xiàn)多個圖標(biāo)的幾種方式,其中包括了多Activity + intent-filter方式、activity-alias方式以及網(wǎng)頁標(biāo)簽-添加快捷方式,分別給出了詳細(xì)的示例代碼,需要的朋友可以參考借鑒。
    2017-05-05
  • android仿iphone主題效果的主菜單

    android仿iphone主題效果的主菜單

    這篇文章主要為大家詳細(xì)介紹了android仿iphone主題效果的主菜單,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Android 單雙擊實(shí)現(xiàn)的方法步驟

    Android 單雙擊實(shí)現(xiàn)的方法步驟

    這篇文章主要介紹了Android 單雙擊實(shí)現(xiàn)的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • Android客戶端實(shí)現(xiàn)注冊、登錄詳解(2)

    Android客戶端實(shí)現(xiàn)注冊、登錄詳解(2)

    這篇文章主要為大家詳細(xì)介紹了Android客戶端實(shí)現(xiàn)注冊、登錄代碼第二篇,App與服務(wù)器的交互實(shí)現(xiàn)登錄和自動登錄功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android手勢控制實(shí)現(xiàn)縮放、移動圖片

    Android手勢控制實(shí)現(xiàn)縮放、移動圖片

    這篇文章主要為大家詳細(xì)介紹了Android手勢控制實(shí)現(xiàn)縮放、移動圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-02-02
  • Android WebView基礎(chǔ)應(yīng)用詳解

    Android WebView基礎(chǔ)應(yīng)用詳解

    這篇文章主要為大家介紹了Android中WebView這一控件的基礎(chǔ)應(yīng)用,例如:播放音樂,播放視頻等,文中的示例代碼講解詳細(xì),對于我們了解WebView很有幫助,需要的同學(xué)可以學(xué)習(xí)一下
    2021-12-12

最新評論

五家渠市| 时尚| 黔南| 南澳县| 邳州市| 旬阳县| 土默特左旗| 沁源县| 思茅市| 香港 | 泰来县| 沁源县| 平湖市| 镇巴县| 武强县| 林州市| 龙里县| 郁南县| 苏尼特右旗| 若羌县| 泽州县| 崇礼县| 松桃| 浙江省| 阿坝| 洛阳市| 观塘区| 渑池县| 玛纳斯县| 望城县| 武威市| 盐源县| 信丰县| 云龙县| 竹北市| 武鸣县| 西宁市| 高尔夫| 东兴市| 泰和县| 霸州市|