編輯:關於Android編程
幾個常用的方法:
1.setTitle()
設置對話框顯示的標題。
2.setIcon()
設置對話框的圖標,值得注意的是,如果沒有使用setTitle()方法,setIcon()不會生效。
3.setMessage()
設置對話框顯示內容。
4.setPositiveButton()、setNegativeButton()、setNeutralButton()
設置對話框的按鈕。
5.setCancelable()
點擊對話框以外,對話框不會消失,按返回鍵對話框也不會消失。
提示對話框
演示實例:
MainActivity.java
public class MainActivity extends Activity { Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setMessage(這是一個提示框); builder.setIcon(R.drawable.icon); builder.setTitle(提示); builder.setPositiveButton(Positive, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); builder.setNegativeButton(Negative, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub } }); builder.setNeutralButton(Neutral, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub } }); builder.show(); } }
演示實例:
MainActivity.java
public class MainActivity extends Activity { Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); //builder.setMessage(我是提示對話框); 設置setMessage後,setItems失效 builder.setIcon(R.drawable.icon); builder.setTitle(提示); builder.setItems(new String[] { one, two, three }, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int index) { String str = null; switch (index) { case 0: str = one; break; case 1: str = two; break; case 2: str = three; break; } Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show(); } }); builder.show(); } }
演示實例:
MainActivity.java
public class MainActivity extends Activity { Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setIcon(R.drawable.icon); builder.setTitle(提示); builder.setSingleChoiceItems(new String[] { one, two, three }, 0, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int index) { String str = null; switch (index) { case 0: str = one; break; case 1: str = two; break; case 2: str = three; break; } Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show(); } }); builder.setPositiveButton(確認, null); builder.show(); } }activity_main.xml
演示實例:
MainActivity.java
public class MainActivity extends Activity { Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setIcon(R.drawable.icon); builder.setTitle(提示); final boolean[] items = new boolean[] { false, false, false }; builder.setMultiChoiceItems(new String[] { one, two, three }, items, new OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface arg0, int arg1, boolean isCheaked) { } }); builder.setPositiveButton(確認, null); builder.show(); } }activity_main.xml
自定義對話框
MainActivity.java
public class MainActivity extends Activity { Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(提示); builder.setIcon(R.drawable.icon); ImageView imageView = new ImageView(MainActivity.this); imageView.setImageResource(R.drawable.close); //獲取布局文件 View myView = this.getLayoutInflater().inflate(R.layout.form, null); builder.setView(myView); ListView listView = (ListView) myView.findViewById(R.id.lv); ArrayAdapteradapter = new ArrayAdapter ( MainActivity.this, android.R.layout.simple_list_item_1, new String[] { 1, 2, 3 }); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView arg0, View arg1, int positon, long arg3) { Toast.makeText(MainActivity.this,+ positon, Toast.LENGTH_SHORT) .show(); } }); builder.setPositiveButton(確認, null); builder.show(); } }
1. 默認為debug mode,使用的簽名文件在: $HOME/.android/debug.keystore 2. Release Mode 簽
離線緩存是指在有網絡的狀態下將從服務器獲取的網絡數據,如Json 數據緩存到本地,在斷網的狀態下啟動APP時讀取本地緩存數據顯示在界面上,常用的APP(網易新聞、知乎等等
一、簡介 1、地圖 地圖展示:普通地圖(2D,3D)、衛星圖和實時交通圖。 地圖操作:可通過接口或手勢控制來實現地圖的點擊、雙擊、長按、縮放
簡介RecyclerView是Google在android-supportv7包中推出的一個新的控件,該控件的主要作用是用於替代ListView、GridView,相比較