編輯:關於Android編程
廢話不多說,直接上代碼
主界面布局
自定義Dialog的布局
public class MainDialog extends Activity implements Runnable{ /**確定取消信息框 **/ private static final int DIALOG_0 = 1; /**多個按鈕信息框 **/ private static final int DIALOG_1 = 2; /**列表框 **/ private static final int DIALOG_2 = 3; /**進度條框 **/ private static final int DIALOG_3 = 4; /**單項選擇列表框 **/ private static final int DIALOG_4 = 5; /**多項選擇列表框 **/ private static final int DIALOG_5 = 6; /**自定義布局 **/ private static final int DIALOG_6 = 7; /**讀取進度框 **/ private static final int DIALOG_7 = 8; private static final int MAX_PROGRESS = 100; private ProgressDialog mProgressDialog = null; final String[] mItems = {"item0","item1","itme2","item3","itme4","item5","item6"}; int mSingleChoiceID = -1; ArrayListMultiChoiceID = new ArrayList (); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button0 = (Button) findViewById(R.id.button0); button0.setOnClickListener(new OnClickListener() { public void onClick(View v) { CreatDialog(DIALOG_0); } }); Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new OnClickListener() { public void onClick(View v) { CreatDialog(DIALOG_1); } }); Button button2 = (Button) findViewById(R.id.button2); button2.setOnClickListener(new OnClickListener() { public void onClick(View v) { CreatDialog(DIALOG_2); } }); Button button3 = (Button) findViewById(R.id.button3); button3.setOnClickListener(new OnClickListener() { public void onClick(View v) { CreatDialog(DIALOG_3); mProgressDialog.setProgress(0); } }); Button button4 = (Button) findViewById(R.id.button4); button4.setOnClickListener(new OnClickListener() { public void onClick(View v) { CreatDialog(DIALOG_4); } }); Button button5 = (Button) findViewById(R.id.button5); button5.setOnClickListener(new OnClickListener() { public void onClick(View v) { CreatDialog(DIALOG_5); } }); Button button6 = (Button) findViewById(R.id.button6); button6.setOnClickListener(new OnClickListener() { public void onClick(View v) { CreatDialog(DIALOG_6); } }); Button button7 = (Button) findViewById(R.id.button7); button7.setOnClickListener(new OnClickListener() { public void onClick(View v) { CreatDialog(DIALOG_7); } }); } public void CreatDialog(int id) { AlertDialog.Builder builder = new AlertDialog.Builder(MainDialog.this); switch(id) { case DIALOG_0: builder.setIcon(R.drawable.icon); builder.setTitle("你確定要離開嗎?"); builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //這裡添加點擊確定後的邏輯 showDialog("你選擇了確定"); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //這裡添加點擊確定後的邏輯 showDialog("你選擇了取消"); } }); break; case DIALOG_1: builder.setIcon(R.drawable.icon); builder.setTitle("投票"); builder.setMessage("您認為什麼樣的內容能吸引您?"); builder.setPositiveButton("有趣味的", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { showDialog("你選擇了有趣味的"); } }); builder.setNeutralButton("有思想的", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { showDialog("你選擇了有思想的"); } }); builder.setNegativeButton("主題強的", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { showDialog("你選擇了主題強的"); } }); break; case DIALOG_2: builder.setTitle("列表選擇框"); builder.setItems(mItems, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //點擊後彈出窗口選擇了第幾項 showDialog("你選擇的id為" + which + " , " + mItems[which]); } }); break; case DIALOG_3: mProgressDialog = new ProgressDialog(MainDialog.this); mProgressDialog.setIcon(R.drawable.icon); mProgressDialog.setTitle("進度條窗口"); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); mProgressDialog.setMax(MAX_PROGRESS); mProgressDialog.setButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //這裡添加點擊後的邏輯 } }); mProgressDialog.setButton2("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //這裡添加點擊後的邏輯 } }); mProgressDialog.show(); new Thread(this).start(); return; case DIALOG_4: mSingleChoiceID = -1; builder.setIcon(R.drawable.icon); builder.setTitle("單項選擇"); builder.setSingleChoiceItems(mItems, 0, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mSingleChoiceID = whichButton; showDialog("你選擇的id為" + whichButton + " , " + mItems[whichButton]); } }); builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if(mSingleChoiceID > 0) { showDialog("你選擇的是" + mSingleChoiceID); } } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); break; case DIALOG_5: MultiChoiceID.clear(); builder.setIcon(R.drawable.icon); builder.setTitle("多項選擇"); builder.setMultiChoiceItems(mItems, new boolean[]{false, false, false, false, false, false, false}, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) { if(isChecked) { MultiChoiceID.add(whichButton); showDialog("你選擇的id為" + whichButton + " , " + mItems[whichButton]); }else { MultiChoiceID.remove(whichButton); } } }); builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String str = ""; int size = MultiChoiceID.size(); for (int i = 0 ;i < size; i++) { str+= mItems[MultiChoiceID.get(i)] + ", "; } showDialog("你選擇的是" + str); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); break; case DIALOG_6: LayoutInflater factory = LayoutInflater.from(this); final View textEntryView = factory.inflate(R.layout.test, null); builder.setIcon(R.drawable.icon); builder.setTitle("自定義輸入框"); builder.setView(textEntryView); builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { EditText userName = (EditText) textEntryView.findViewById(R.id.etUserName); EditText password = (EditText) textEntryView.findViewById(R.id.etPassWord); showDialog("姓名 :" + userName.getText().toString() + "密碼:" + password.getText().toString() ); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); break; case DIALOG_7: mProgressDialog = new ProgressDialog(this); mProgressDialog.setTitle("讀取ing"); mProgressDialog.setMessage("正在讀取中請稍候"); mProgressDialog.setIndeterminate(true); mProgressDialog.setCancelable(true); mProgressDialog.show(); return; } builder.create().show(); } private void showDialog(String str) { new AlertDialog.Builder(MainDialog.this) .setMessage(str) .show(); } @Override public void run() { int Progress = 0; while(Progress < MAX_PROGRESS) { try { Thread.sleep(100); Progress++; mProgressDialog.incrementProgressBy(1); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
Android Studio快速提取方法 在開發過程中,有時在一個方法內部寫了過多的代碼,然後想要把一些代碼提取出來封裝下,分離開放在一個單獨的方法裡,可能你的
效果圖源碼KqwOpenCVBlurDemo阈值化是一種將我們想要在圖像中分析的區域分割出來的方法。我們把每個像素值都與一個預設的阈值做比較,再根據比較的結果調整像素值。
第一步:下載SDK:1下載地址:http://www.mob.com/ 根據需求選擇需要的平台:第二步:申請ShareSDK的AppKey把鼠標移到頭像上,點擊進入後台:
介紹圓角控件常用於頭像,按鈕,圖標等,用途十分廣泛,而且常常配合board使用。在IOS中,UIVIew的CALayer層已經提供了圓角和board的方法,所以圓角控件的