Android常用代码

106 篇文章 0 订阅

1 给文本框设置内容


TextView txtResult = (TextView) findViewById(R.id.txtResult);
txtResult.setText(“我是徐海涛”);


2 查找View

findViewById(R.id.setting).setVisibility(View.GONE);


3 意图

若果意图过滤器中没有定义data,只定义action和category,那么Intent中的动作action和范畴category只要出现在意图过滤器intent-filter中,即可激活Activity,intent是过滤器的子集)

如果一个Activity的意图过滤器中定义了data(scheme/host/path/mimeType),那么意图中必须完全按照过滤器的data要求出示,否则无法激活Activity


接收端取出数据
Intent intent=this.getIntent();
bunde = intent.getExtras();
String sex = bundle.getString(“sex”);
Double height = bundle.getDouble(“height”);
Bundle2.this.setResult(RESULT_OK,intent);
Bundle2.this.finish();


4 线性布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:layout_height="fill_parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="18dp"
        android:padding="8dp"
        android:id="@+id/txtResult" />

    <View
        android:layout_width="match_parent"
        android:background="#999"
        android:layout_height="25dp" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_above="@+id/btn"
        android:layout_weight="1"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textSize="12dp"
            android:id="@+id/txtLog" />
    </ScrollView>


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/setting"
        android:id="@+id/setting"
        android:onClick="onClick"
        android:layout_alignParentBottom="true" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/start"
        android:id="@+id/btn"
        android:onClick="onClick"
        android:layout_alignParentBottom="true" />

</LinearLayout>

线性布局案例二

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:orientation="vertical"
              android:layout_height="fill_parent">

    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="slot name"
            android:id="@+id/textView2" android:layout_gravity="center_horizontal"/>
    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="words"
            android:id="@+id/textView" android:layout_gravity="center_horizontal"/>
    <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="status"
            android:id="@+id/textView3" android:layout_gravity="center_horizontal"/>
    <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="submit"
            android:id="@+id/button"/>
</LinearLayout>

FR:海涛高软(QQ群:386476712)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值