編輯:關於Android編程
續: 話說道哥跟發哥在上海柯炫做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); ArrayListlistSheetItems = new ArrayList (); 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 ListlistSheetItems; 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 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; } } }
PopupMenu基本用法PopupMenu是種顯示位置不固定的彈出菜單,因為它顯示在參照控件下方,所以展示位置隨著參照控件的位置變化而變化。而其他幾種菜單的顯示位置都是
Android測試支持庫包含 UI自動化模塊 ,它可以對Android應用進行自動黑盒測試。在API Level 18中引入了自動化模塊,它允許開發者在組成應用UI的控件
簡介:基本概念:Service是Android四大組件之一,運行在後台執行耗時操作並且不提供用戶界面。其他組件(如Activity)可以通過startService啟動該
ActionBar是3.0後的UI設計規范,同時也是Google極力推薦使用的設計風格,如何快速設計一個入眼的ActionBar呢,更進一步,給我們搭好一個入眼的Acti