Android Crash Learning

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值