今天介绍一个自己做的快递单号查询的简单APP,供大家参考。由于需要使用http和json,本文在build.gradle(module:app)添加了okhttp3依赖和gson依赖。
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:24.1.1' testCompile 'junit:junit:4.12' compile 'com.squareup.okhttp3:okhttp:3.6.0' compile 'com.google.code.gson:gson:2.2.4' }看一下布局文件
ListView使用的item的布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/time_text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="bold" android:textAppearance="?android:textAppearanceMedium" android:typeface="monospace"/> <TextView android:id="@+id/context_text_view" android:layout_width="match_parent" android:layout_height="50dp" android:textAppearance="?android:textAppearanceSmall" android:typeface="monospace"/> </LinearLayout>资源文件,首先是strings.xml
<resources> <string name="app_name">快递查询</string> <string name="please_enter_delivery_no">请输入快递单号</string> <string name="query">查询</string> <string name="query_url">http://.yjp.deliverynoquerydemo"> <uses-permission android:name="android.permission.INTERNET" /> <application android:name=".global.MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:windowSoftInputMode="stateHidden"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>主要是替换了默认的Application类,然后让MainActivity默认不弹出软键盘。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。