实验二--任务一--打招呼
来源:互联网 发布:淘宝联盟好用吗 编辑:程序博客网 时间:2024/06/05 07:02
一.运行效果图
二.主要代码:
1.MainActivity.java
package cn.edu.bzu.helloandroid; import android.app.Activity; import android.content.Context; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private Button btnClick; private EditText etName; private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main) ; btnClick=(Button) findViewById(R.id.btnClick); btnClick.setOnClickListener(new ClickHandler()); etName=(EditText) findViewById(R.id.etName); } class ClickHandler implements OnClickListener { @Override public void onClick(View view) { String name=etName.getText().toString(); Toast toast=Toast.makeText(getApplicationContext(), "hello"+name,Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 400); ImageView imageView= new ImageView(getApplicationContext()); imageView.setImageResource(R.drawable.smile); LinearLayout toastView = (LinearLayout) toast.getView(); toastView.setOrientation(LinearLayout.HORIZONTAL); toastView.addView(imageView, 0); toast.show(); } } }
2.布局代码
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" [html] view plain copyandroid:background="@drawable/bg" <span style="font-family: Arial, Helvetica, sans-serif;"> ></span> [html] view plain copy <EditText android:id="@+id/etName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="82dp" android:layout_marginTop="74dp" android:background="@android:drawable/edit_text" android:drawableLeft="@drawable/name" android:ems="10" android:hint="@string/etNamePrompt" > <requestFocus /> </EditText> <Button android:id="@+id/btnClick" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/etName" android:layout_below="@+id/etName" android:layout_marginLeft="60dp" android:layout_marginTop="40dp" android:background="@drawable/handok" /> </RelativeLayout>
3.配置文件
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.edu.bzu.helloandroid" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="cn.edu.bzu.helloandroid.MainActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
三.实验总结
本次实验的主要任务就是自定义一个toast,因为原生的toast不能满足要求。本次实验要实现的toast效果是:四角要是圆角,且toast里同时包含图片和文字,图片和文字并排显示,点击imageButton,显示“hello+输入的内容“,且toast显示时间较长。
0 0
- 实验二.任务一.打招呼
- 实验二--任务一--打招呼
- 实验二 任务一 打招呼APP
- 实验二任务1打招呼
- 实验二 任务1 打招呼
- 实验二——任务一——打招呼
- 初学移动开发技术_实验二_任务一_打招呼
- 安卓学习 实验二任务一 ——————打招呼
- 实验任务1 打招呼
- 实验一 Toast 打招呼
- 任务一,打招呼。
- 安卓任务二打招呼
- 实验二任务一
- 实验二-任务一
- Android实验任务——打招呼
- 实验二—任务一
- Activity和Intent 任务一 打招呼
- 实验二———任务一
- 架构设计:系统存储(14)——MySQL横向拆分与业务透明化(2)
- Weblogic-学习笔记(1-2课)
- eclipse管理多个workspace
- 在WIFI下获取手机的IP地址
- 第9周项目3-(1)稀疏矩阵的三元组表示的实现及应用
- 实验二--任务一--打招呼
- Spring注解方式防止表单重复提交
- jcifs- 读取网络共享文件图片资源
- Testing Storage Spaces Direct using Dell PowerEdge R730xd
- 第十三周项目一(Prim算法的验证和Kruskal算法的验证)
- 如何设置默认输入法
- leetcode 447. Number of Boomerangs
- 简谈我所理解的面向对象
- Information-Centric Network