android:Toast和Intent的用法
来源:互联网 发布:编程有哪些语言 编辑:程序博客网 时间:2024/06/06 00:30
Toast的用法:
在button上使用toast;
在布局中建立好button并取名button1。
在oncreate部分的代码
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first_layout); Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener(){//注册监听器 @Override public void onClick(View v) { makeText(FristActivity.this,"You clicked Button1", LENGTH_SHORT).show();//有两个变量可选,Toast.LENGTH_SHORT和 Toast_LENGHT_LONG,表示显示的时长 }}
Intent的用法
显示intent
在按钮的点击事件中使用显示intent从当前活动跳到另一个活动中
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first_layout); Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { makeText(FristActivity.this,"You clicked Button1", LENGTH_SHORT).show(); //finish();销毁活动 Intent intent=new Intent(FirstActivity.this,SecondActivity.class);//显示intent startActivity(intent); } }); }
隐式intent的用法
现在AndroidMainfest.xml中添加代码
<activity android:name=".SecondActivity"> <intent-filter> <action android:name="com.example.activitytest.ACTION_START"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>
然后改掉按钮点击事件中的代码
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first_layout); Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { makeText(FristActivity.this,"You clicked Button1", LENGTH_SHORT).show(); //finish();销毁活动 Intent intent=new Intent("com.example.activitytest.ACTION_START");//改动的位置 startActivity(intent); } }); }
和显示调用intent一样会启动另一个活动;
阅读全文
0 0
- android:Toast和Intent的用法
- android-Toast的用法
- Android Toast 的用法
- 【android】Toast 的用法
- Android:Toast的用法
- Android中关于Intent filter和Intent的一些用法。
- Android之Toast的用法
- Android中Toast的用法
- Android-- Toast通知的用法
- Android Intent的用法
- Android Intent的用法
- Toast的功能和用法
- Toast和menu的用法
- Toast 位置的改变 和 Toast的简单用法
- Android中Intent的setData,setType和setDataAndType的用法
- Android中Intent的setData,setType和setDataAndType的用法
- Android中Intent的setData,setType和setDataAndType的用法
- Android中Intent的setData,setType和setDataAndType的用法
- ActiveMQ持久订阅设置
- scrollview的contentoffset自动偏移问题
- 解决Eclipse中SVN版本信息不显示的问题
- swagger学习之路
- js60秒倒计时防刷新
- android:Toast和Intent的用法
- 单例模式的七种写法
- Linux下Redis的安装和部署
- Window 对象
- CSS3-2
- 如何优雅的抓取低功耗蓝牙BLE的数据
- 编译出现错误:linker command failed with exit code 1 (use -v to see invocation)
- hackerRank上的一道题,如何更快
- 二分查找算法