android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果(4)
有点长,不过注释都写的很清楚了。show()方法完成窗口的弹出。里面调用其他方法设置了窗口弹出的位置,设置了相应的动画弹出风格和箭头朝向以及位置,创建了action item。大家可以从这个方法里开始看,看每个的实现。
最后写个测试类。放一个Button在屏幕顶部,一个在屏幕底部。点击弹出弹窗。
package com.notice.quickaction;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;/** * 实现activity */public class MyQuick extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // 得到一个actionItem对象 final ActionItem chart = new ActionItem(); // 设置标题,图标,点击事件 chart.setTitle("Chart"); chart.setIcon(getResources().getDrawable(R.drawable.chart)); chart.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MyQuick.this, "Chart selected", Toast.LENGTH_SHORT).show(); } }); final ActionItem production = new ActionItem(); production.setTitle("Products"); production.setIcon(getResources().getDrawable(R.drawable.production)); production.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MyQuick.this, "Products selected", Toast.LENGTH_SHORT).show(); } }); Button btn1 = (Button) this.findViewById(R.id.btn1); // 点击按钮弹出 btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 初始化一个QuickActions QuickActions qa = new QuickActions(v); // 为他添加actionitem qa.addActionItem(chart); qa.addActionItem(production); qa.addActionItem(production); qa.addActionItem(production); // 设置动画风格 qa.setAnimStyle(QuickActions.ANIM_AUTO); qa.show(); } }); final ActionItem dashboard = new ActionItem(); dashboard.setIcon(getResources().getDrawable(R.drawable.dashboard)); dashboard.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MyQuick.this, "dashboard selected", Toast.LENGTH_SHORT).show(); } }); final ActionItem users = new ActionItem(); users.setIcon(getResources().getDrawable(R.drawable.users)); users.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MyQuick.this, "Products selected", Toast.LENGTH_SHORT).show(); } }); Button btn2 = (Button) this.findViewById(R.id.btn2); btn2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { QuickActions qa = new QuickActions(v); qa.addActionItem(dashboard); qa.addActionItem(users); qa.setAnimStyle(QuickActions.ANIM_GROW_FROM_CENTER); qa.show(); } }); }}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>