Android Crash Learning
1.LinearLayout
<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=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:layout_width="160dp"
android:layout_height="90dp"
android:src="@drawable/react" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕" />
</LinearLayout>
2.RelativeLayout
<RelativeLayout 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=".MainActivity">
<TextView
android:layout_margin="50dp"
android:id="@+id/greeting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Greeting!"
android:textSize="50dp"/>
<TextView
android:layout_margin="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GoodBye!"
android:layout_below="@+id/greeting"
android:textSize="50dp"/>
</RelativeLayout>
3.Toast
Toast.makeText(getApplicationContext(), "哈哈哈", Toast.LENGTH_LONG).show();
4.Click
public void btn1(View view) {
Toast.makeText(getApplicationContext(), "哈哈哈", Toast.LENGTH_LONG).show();
}
// 接着設置一下按鈕的onClick屬性
5.Intent跳轉
Intent intent = new Intent(LoginActivity.this, CommonMenuActivity.class);
startActivity(intent);
在manifest中需要聲明
<activity android:name=".pages.CommonMenuActivity"></activity>
6.攜帶數據跳轉
// 傳輸數據
Intent intent = new Intent(LoginActivity.this, CommonMenuActivity.class);
intent.putExtra("key", "value");
// 獲取數據
Bundle bundle = getIntent().getExtras();
bundle.getString("key");
// 繼承Serializable的對象可以直接
intent.putExtra("key", obj);
Item item = (Item)bundle.getSerializable("key");
7.API調用
見Github使用OkHttp