标签:android style blog http io color ar os sp
续: 话说道哥跟发哥在上海柯炫做Android开发,看来跟发哥差距很大。总结了下发哥的技术拿来这里装逼用用。
参考这里: http://blog.csdn.net/xiechengfa/article/details/40373331
package com.zf.iosdialog; import java.util.ArrayList; 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; import com.zf.iosdialog.bean.SheetItem; import com.zf.iosdialog.widget.IosDialog; public class MainActivity extends Activity implements OnClickListener, OnSheetMyItemClickListner { private Button btn1; private Button btn2; private Button btn3; private Button btn4; private Button btn5; /*** * weixinNumber: lixiaodaoaaa weibo:www.weibo.com/lixiaodaoaaa thanks * :xiechengfa */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { btn1 = (Button) findViewById(R.id.btn1); btn1.setOnClickListener(this); btn2 = (Button) findViewById(R.id.btn2); btn2.setOnClickListener(this); btn3 = (Button) findViewById(R.id.btn3); btn3.setOnClickListener(this); btn4 = (Button) findViewById(R.id.btn4); btn4.setOnClickListener(this); btn5 = (Button) findViewById(R.id.btn5); btn5.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn5 : IosDialog iosDialog = new IosDialog(MainActivity.this); ArrayList<SheetItem> listSheetItems = new ArrayList<SheetItem>(); listSheetItems.add(new SheetItem("shabi001", 1)); listSheetItems.add(new SheetItem("shabi002", 2)); listSheetItems.add(new SheetItem("shabi003", 3)); listSheetItems.add(new SheetItem("shabi004", 4)); listSheetItems.add(new SheetItem("shabi005", 5)); listSheetItems.add(new SheetItem("shabi006", 6)); iosDialog.setSheetItems(listSheetItems, MainActivity.this); iosDialog.show(); break; default : break; } } @Override public void onClickItem(int which) { switch (which) { case 1 : Toast.makeText(this, "lixiaodaoaaa001", Toast.LENGTH_SHORT).show(); break; case 2 : Toast.makeText(this, "lixiaodaoaaa002", Toast.LENGTH_SHORT).show(); break; case 3 : Toast.makeText(this, "lixiaodaoaaa003", Toast.LENGTH_SHORT).show(); break; case 4 : Toast.makeText(this, "lixiaodaoaaa004", Toast.LENGTH_SHORT).show(); break; case 5 : Toast.makeText(this, "lixiaodaoaaa005", Toast.LENGTH_SHORT).show(); break; case 6 : Toast.makeText(this, "lixiaodaoaaa006", Toast.LENGTH_SHORT).show(); break; default : break; } } }
IOSDialog代码(防这个效果)
package com.zf.iosdialog.widget; import java.util.List; import android.app.Dialog; import android.content.Context; import android.graphics.Color; import android.view.Display; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.view.WindowManager; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.ScrollView; import android.widget.TextView; import com.zf.iosdialog.OnSheetMyItemClickListner; import com.zf.iosdialog.R; import com.zf.iosdialog.bean.SheetItem; public class IosDialog { private Context context; private Dialog dialog; private TextView txt_title; private TextView txt_cancel; private LinearLayout lLayout_content; private ScrollView sLayout_content; private boolean showTitle = false; private List<SheetItem> listSheetItems; private Display display; public IosDialog(Context context) { this.context = context; WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); display = windowManager.getDefaultDisplay(); builder(); } public IosDialog builder() { // 获取Dialog布局 View view = LayoutInflater.from(context).inflate(R.layout.view_actionsheet, null); // 设置Dialog最小宽度为屏幕宽度 view.setMinimumWidth(display.getWidth()); // 获取自定义Dialog布局中的控件 sLayout_content = (ScrollView) view.findViewById(R.id.sLayout_content); lLayout_content = (LinearLayout) view.findViewById(R.id.lLayout_content); txt_title = (TextView) view.findViewById(R.id.txt_title); txt_cancel = (TextView) view.findViewById(R.id.txt_cancel); txt_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); // 定义Dialog布局和参数 dialog = new Dialog(context, R.style.ActionSheetDialogStyle); dialog.setContentView(view); Window dialogWindow = dialog.getWindow(); dialogWindow.setGravity(Gravity.LEFT | Gravity.BOTTOM); WindowManager.LayoutParams lp = dialogWindow.getAttributes(); lp.x = 0; lp.y = 0; dialogWindow.setAttributes(lp); return this; } public IosDialog setTitle(String title) { showTitle = true; txt_title.setVisibility(View.VISIBLE); txt_title.setText(title); return this; } public IosDialog setCancelable(boolean cancel) { dialog.setCancelable(cancel); return this; } public IosDialog setCanceledOnTouchOutside(boolean cancel) { dialog.setCanceledOnTouchOutside(cancel); return this; } /** 设置条目布局 */ public void setSheetItems(List<SheetItem> sheetItemList, final OnSheetMyItemClickListner itemLisenner) { this.listSheetItems = sheetItemList; if (sheetItemList == null || sheetItemList.size() <= 0) { return; } int size = sheetItemList.size(); // TODO 高度控制,非最佳解决办法 // 添加条目过多的时候控制高度 if (size >= 7) { LinearLayout.LayoutParams params = (LayoutParams) sLayout_content.getLayoutParams(); params.height = display.getHeight() / 2; sLayout_content.setLayoutParams(params); } // 循环添加条目 for (int i = 1; i <= size; i++) { final int index = i; final SheetItem sheetItem = sheetItemList.get(i - 1); String strItem = sheetItem.getStrItemName(); TextView textView = new TextView(context); textView.setText(strItem); textView.setTextSize(18); textView.setGravity(Gravity.CENTER); // 背景图片 if (size == 1) { if (showTitle) { textView.setBackgroundResource(R.drawable.actionsheet_bottom_selector); } else { textView.setBackgroundResource(R.drawable.actionsheet_single_selector); } } else { if (showTitle) { if (i >= 1 && i < size) { textView.setBackgroundResource(R.drawable.actionsheet_middle_selector); } else { textView.setBackgroundResource(R.drawable.actionsheet_bottom_selector); } } else { if (i == 1) { textView.setBackgroundResource(R.drawable.actionsheet_top_selector); } else if (i < size) { textView.setBackgroundResource(R.drawable.actionsheet_middle_selector); } else { textView.setBackgroundResource(R.drawable.actionsheet_bottom_selector); } } } textView.setTextColor(Color.parseColor(SheetItemColor.Blue.getName())); // 高度 float scale = context.getResources().getDisplayMetrics().density; int height = (int) (45 * scale + 0.5f); textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height)); // 点击事件 textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { itemLisenner.onClickItem(sheetItem.getITEM_CODE()); dialog.dismiss(); } }); lLayout_content.addView(textView); } } public void show() { dialog.show(); } public interface OnSheetItemClickListener { void onClick(int which); } public enum SheetItemColor { Blue("#037BFF"), Red("#FD4A2E"); private String name; private SheetItemColor(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } } }
android实现 仿iphoneDialog实现类似于iphone对话框样式
标签:android style blog http io color ar os sp
原文地址:http://blog.csdn.net/lixiaodaoaaa/article/details/41121713