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

android查看網絡圖片的實現方法

 更新時間:2019年04月18日 14:12:05   作者:ITzhongzi  
這篇文章主要為大家詳細介紹了android查看網絡圖片的實現方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了android查看網絡圖片的具體代碼,供大家參考,具體內容如下

需求描述: 輸入一個 圖片地址,下載到本地 展示。

效果展示

代碼清單

MainActivity.java

package com.example.www.checkimage;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class MainActivity extends AppCompatActivity {

 private EditText mPt_url;
 private ImageView mIv_show;
 private Handler mHandler = new Handler(){
 @Override
 public void handleMessage(Message msg) {
 if(msg.what == 1){
 Bitmap bitmap = (Bitmap) msg.obj;
 mIv_show.setImageBitmap(bitmap);
 Toast.makeText(getApplicationContext(), "圖片展示成功", Toast.LENGTH_LONG).show();
 }
 }
 };

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 mPt_url = (EditText) findViewById(R.id.pt_url);
 mIv_show = (ImageView) findViewById(R.id.imageCon);
 }

 public void checkImage(View v) {
 new Thread(){
 @Override
 public void run() {

 try {
  String path = mPt_url.getText().toString().trim();
  URL url = new URL(path);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod("GET");
  conn.setConnectTimeout(5000);
  int responseCode = conn.getResponseCode();
  if(responseCode == 200) {
  InputStream is = conn.getInputStream();


  Bitmap bitmap = BitmapFactory.decodeStream(is);

  Message msg = Message.obtain(); // 創(chuàng)建 消息
  msg.obj = bitmap;
  msg.what = 1;


  mHandler.sendMessage(msg);
  }
 } catch (Exception e) {
  e.printStackTrace();
 }

 }
 }.start();
 }
}

activiity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
 tools:context=".MainActivity">

 <EditText
 android:id="@+id/pt_url"
 android:layout_width="368dp"
 android:layout_height="wrap_content"
 android:layout_marginStart="8dp"
 android:layout_marginTop="8dp"
 android:layout_marginEnd="8dp"
 android:ems="10"
 android:hint="請輸入與圖片地址"
 android:inputType="textPersonName"
 app:layout_constraintEnd_toEndOf="parent"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toTopOf="parent" />

 <Button
 android:id="@+id/button"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginStart="8dp"
 android:layout_marginTop="8dp"
 android:layout_marginEnd="8dp"
 android:text="Button"
 app:layout_constraintEnd_toEndOf="parent"
 app:layout_constraintHorizontal_bias="0.0"
 app:layout_constraintStart_toStartOf="parent"
 android:onClick="checkImage"
 app:layout_constraintTop_toBottomOf="@+id/pt_url" />

 <ImageView
 android:id="@+id/imageCon"
 android:layout_width="0dp"
 android:layout_height="0dp"
 android:layout_marginStart="8dp"
 android:layout_marginTop="8dp"
 android:layout_marginEnd="8dp"
 android:layout_marginBottom="8dp"
 app:layout_constraintBottom_toBottomOf="parent"
 app:layout_constraintEnd_toEndOf="parent"
 app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintTop_toBottomOf="@+id/button"
 app:srcCompat="@mipmap/ic_launcher" />
</android.support.constraint.ConstraintLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.www.checkimage">

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

 <application
 android:allowBackup="true"
 android:icon="@mipmap/ic_launcher"
 android:label="@string/app_name"
 android:roundIcon="@mipmap/ic_launcher_round"
 android:supportsRtl="true"
 android:theme="@style/AppTheme">
 <activity android:name=".MainActivity">
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />

 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>
 </application>

</manifest>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Android自定義View實現跟隨手指移動的小兔子

    Android自定義View實現跟隨手指移動的小兔子

    這篇文章主要為大家詳細介紹了Android自定義View實現跟隨手指移動的小兔子,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • Android自定義滾動選擇器實例代碼

    Android自定義滾動選擇器實例代碼

    本篇文章主要介紹了Android自定義滾動選擇器實例代碼,具有一定的參考價值,有興趣的可以了解一下。
    2017-01-01
  • android WebView組件使用總結

    android WebView組件使用總結

    瀏覽器控件是每個開發(fā)環(huán)境都具備的,這為馬甲神功提供了用武之地,windows的有webbrowser,android和ios都有webview;本篇主要介紹android的webview之強大,感興趣的朋友可以研究下
    2012-12-12
  • Android APK應用安裝原理解析之AndroidManifest使用PackageParser.parserPackage原理分析

    Android APK應用安裝原理解析之AndroidManifest使用PackageParser.parserPac

    這篇文章主要介紹了Android APK應用安裝原理解析之AndroidManifest使用PackageParser.parserPackage原理,結合實例形式分析了PackageManagerService調用PackageParser.parserPackage方法解析APK清單相關原理與操作技巧,需要的朋友可以參考下
    2017-12-12
  • Android編程實現ListView內容無限循環(huán)顯示的方法

    Android編程實現ListView內容無限循環(huán)顯示的方法

    這篇文章主要介紹了Android編程實現ListView內容無限循環(huán)顯示的方法,通過繼承Adapter類實現ListView中的數據無限循環(huán)顯示功能,需要的朋友可以參考下
    2017-06-06
  • Android控件之RatingBar自定義星級評分樣式

    Android控件之RatingBar自定義星級評分樣式

    RatingBar為評分條控件,默認效果為若干個綠色的星星,如果想將其換成其他自定義圖片就要自定義它的style。接下來通過本文給大家介紹Android控件之RatingBar自定義星級評分樣式,感興趣的朋友一起學習吧
    2016-02-02
  • Android 屬性動畫ValueAnimator與插值器詳解

    Android 屬性動畫ValueAnimator與插值器詳解

    這篇文章主要介紹了Android 屬性動畫ValueAnimator與插值器詳解的相關資料,需要的朋友可以參考下
    2017-05-05
  • Android kotlin使用注解實現防按鈕連點功能的示例

    Android kotlin使用注解實現防按鈕連點功能的示例

    這篇文章主要介紹了Android kotlin使用注解實現防按鈕連點功能的示例,幫助大家更好的理解和學習使用Android,感興趣的朋友可以了解下
    2021-03-03
  • Android Studio多渠道打包、自定義打包APK名稱

    Android Studio多渠道打包、自定義打包APK名稱

    Android Studio為我們提供了簡便的方法,可以多渠道打包,一次打包所有的渠道包。這篇文章主要介紹了Android Studio多渠道打包、自定義打包APK名稱,需要的朋友可以參考下
    2018-01-01
  • Android實現滑動刻度尺效果

    Android實現滑動刻度尺效果

    這篇文章主要為大家詳細介紹了Android實現滑動刻度尺效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-06-06

最新評論

宁波市| 汽车| 锦州市| 兴义市| 霍州市| 原平市| 西安市| 酒泉市| 五华县| 祥云县| 延吉市| 合江县| 香河县| 永济市| 伊春市| 湖口县| 平顶山市| 锡林浩特市| 泰宁县| 平度市| 大田县| 杨浦区| 原平市| 千阳县| 西乌| 赫章县| 永新县| 铁岭市| 肃宁县| 岳池县| 定边县| 泉州市| 象州县| 惠州市| 吉木萨尔县| 辛集市| 德阳市| 浮山县| 铜陵市| 织金县| 五峰|