欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

一、UI設(shè)計(jì)

首頁(yè)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="請(qǐng)選擇城市"
? ? ? ? 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>

效果:

展示頁(yè)面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ù)并上傳至前臺(tái)

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

1.首頁(yè)

代碼如下(示例):

@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.展示頁(yè)面

代碼如下(示例):

@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) {

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

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

相關(guān)文章

  • Android如何禁止向EditText控件中輸入內(nèi)容詳解

    Android如何禁止向EditText控件中輸入內(nèi)容詳解

    EditText是接受用戶輸入信息的最重要控件。下面這篇文章主要給大家介紹了關(guān)于Android如何禁止向EditText控件中輸入內(nèi)容的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-09-09
  • Android 5.0+ 屏幕錄制實(shí)現(xiàn)的示例代碼

    Android 5.0+ 屏幕錄制實(shí)現(xiàn)的示例代碼

    這篇文章主要介紹了Android 5.0+ 屏幕錄制實(shí)現(xiàn)的示例代碼,從 5.0 開始,系統(tǒng)提供給了 app 錄制屏幕的一系列方法,不需要 root 權(quán)限,只需要用戶授權(quán)即可錄屏,相對(duì)來說較為簡(jiǎn)單,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android時(shí)間對(duì)話框TimePickerDialog詳解

    Android時(shí)間對(duì)話框TimePickerDialog詳解

    這篇文章主要為大家詳細(xì)介紹了Android時(shí)間對(duì)話框TimePickerDialog的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android 集成 google 登錄并獲取性別等隱私信息的實(shí)現(xiàn)代碼

    Android 集成 google 登錄并獲取性別等隱私信息的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android 集成 google 登錄并獲取 性別等隱私信息,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-06-06
  • Android繪制雙折線圖的方法

    Android繪制雙折線圖的方法

    這篇文章主要為大家詳細(xì)介紹了Android繪制雙折線圖的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • Android實(shí)現(xiàn)監(jiān)聽音量的變化

    Android實(shí)現(xiàn)監(jiān)聽音量的變化

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)監(jiān)聽音量的變化,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Android傳感器SensorEventListener之加速度傳感器

    Android傳感器SensorEventListener之加速度傳感器

    今天小編就為大家分享一篇關(guān)于Android傳感器SensorEventListener之加速度傳感器,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-02-02
  • Android實(shí)現(xiàn)底部圖片選擇Dialog

    Android實(shí)現(xiàn)底部圖片選擇Dialog

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)底部圖片選擇Dialog,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android基于service實(shí)現(xiàn)音樂的后臺(tái)播放功能示例

    Android基于service實(shí)現(xiàn)音樂的后臺(tái)播放功能示例

    這篇文章主要介紹了Android基于service實(shí)現(xiàn)音樂的后臺(tái)播放功能,結(jié)合實(shí)例形式分析了Android基于Service組件實(shí)現(xiàn)多媒體音頻播放功能的步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2016-10-10
  • Android開發(fā)入門環(huán)境快速搭建實(shí)戰(zhàn)教程

    Android開發(fā)入門環(huán)境快速搭建實(shí)戰(zhàn)教程

    最近想重新學(xué)習(xí)下Android,學(xué)習(xí)之前開發(fā)環(huán)境的搭建是個(gè)首先要解決的問題,所以下面這篇文章主要給大家介紹了Android開發(fā)環(huán)境搭建的相關(guān)資料,文中將實(shí)現(xiàn)的步驟一步步介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11

最新評(píng)論