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