case KeyEvent.KEYCODE_DPAD_CENTER:<br style="word-wrap:break-word;">
&nbsp;&nbsp;Log.i("中",String.valueOf(keyCode));<br style="word-wrap:break-word;">
&nbsp;&nbsp;break;<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
&nbsp;&nbsp;return super.onKeyDown(keyCode, event);<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
122 android 显示正在运行的程序<br style="word-wrap:break-word;">
ActivityManager mActivityManager = (ActivityManager)<br style="word-wrap:break-word;">
getSystemService(ACTIVITY_SERVICE);<br style="word-wrap:break-word;">
List&lt;ActivityManager.RunningTaskInfo&gt; mRunningTasks =&nbsp;<br style="word-wrap:break-word;">
mActivityManager.getRunningTasks(100);<br style="word-wrap:break-word;">
for (ActivityManager.RunningTaskInfo task : mRunningTasks)<br style="word-wrap:break-word;">
{<br style="word-wrap:break-word;">
String taskInfo = task.baseActivity.getClassName()<br style="word-wrap:break-word;">
+"(ID=" + amTask.id +")");<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
123 android 切换横竖屏<br style="word-wrap:break-word;">
if(getRequestedOrientation()==<br style="word-wrap:break-word;">
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)<br style="word-wrap:break-word;">
{<br style="word-wrap:break-word;">
setRequestedOrientation<br style="word-wrap:break-word;">
(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
else if(getRequestedOrientation()==<br style="word-wrap:break-word;">
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)<br style="word-wrap:break-word;">
{<br style="word-wrap:break-word;">
setRequestedOrientation<br style="word-wrap:break-word;">
(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);<br style="word-wrap:break-word;">
}<br style="word-wrap:break-word;">
//PORTRAIT竖;LANDSCAPE横<br style="word-wrap:break-word;">
124 android 判断网络类型是否为GPRS<br style="word-wrap:break-word;">
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);<br style="word-wrap:break-word;">
if(telephonyManager.getNetworkType()==telephonyManager.NETWORK_TYPE_GPRS)<br style="word-wrap:break-word;">
125 android 发送http请求给网页<br style="word-wrap:break-word;">
String uriAPI = "<a style="word-wrap:break-word;color:#336699;" href="http://127.0.0.1:8080/test/index.jsp" target="_blank">http://127.0.0.1:8080/test/index.jsp</a>";<br style="word-wrap:break-word;">
HttpPost httpRequest = new HttpPost(uriAPI);&nbsp;<br style="word-wrap:break-word;">
List &lt;NameValuePair&gt; params = new ArrayList &lt;NameValuePair&gt;();&nbsp;<br style="word-wrap:break-word;">
params.add(new BasicNameValuePair("username", "test"));<br style="word-wrap:break-word;">
try&nbsp;<br style="word-wrap:break-word;">
{&nbsp;<br style="word-wrap:break-word;">
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));&nbsp;<br style="word-wrap:break-word;">
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);&nbsp;<br style="word-wrap:break-word;">
if(httpResponse.getStatusLine().getStatusCode() == 200)&nbsp;&nbsp;<br style="word-wrap:break-word;">
{&nbsp;<br style="word-wrap:break-word;">
String strResult = EntityUtils.toString(httpResponse.getEntity());&nbsp;<br style="word-wrap:break-word;">
}&nbsp;<br style="word-wrap:break-word;">
}&nbsp;<br style="word-wrap:break-word;">
catch (IOException e)&nbsp;<br style="word-wrap:break-word;">
{&nbsp;&nbsp;<br style="word-wrap:break-word;">
e.printStackTrace();&nbsp;<br style="word-wrap:break-word;">
}&nbsp;<br style="word-wrap:break-word;">
126 android 创建带图片的按钮<br style="word-wrap:break-word;">
ImageButton imageButton = new ImageButton(this);<br style="word-wrap:break-word;">
imageButton.setImageResource(R.drawable.test);<br style="word-wrap:break-word;">
127 android 创建WebView<br style="word-wrap:break-word;">
LinearLayout layout = new LinearLayout(this);<br style="word-wrap:break-word;">
Button button = new Button(this);<br style="word-wrap:break-word;">
layout.addView(button);<br style="word-wrap:break-word;">
layout.removeView(button);<br style="word-wrap:break-word;">
128 android layout设置背景图片<br style="word-wrap:break-word;">
LinearLayout layout = new LinearLayout(this);<br style="word-wrap:break-word;">
layout.setBackgroundResource(R.drawable.hh);//图片放在drawable下了,名字是hh.jpg<br style="word-wrap:break-word;">
129 android 设置铃声<br style="word-wrap:break-word;">
Intent intent = new Intent( RingtoneManager.<br style="word-wrap:break-word;">
ACTION_RINGTONE_PICKER);<br style="word-wrap:break-word;">
130 android 设置网络 请求方式/缓存/格式/编码<br style="word-wrap:break-word;">
HttpURLConnection con=(HttpURLConnection)url.openConnection();<br style="word-wrap:break-word;">
con.setUseCaches(false);//不使用缓存<br style="word-wrap:break-word;">
con.setRequestMethod("POST");//请求方式是post<br style="word-wrap:break-word;">
con.setRequestProperty("Content-Type", "text/xml");//格式<br style="word-wrap:break-word;">
con.setRequestProperty("Charset", "UTF-8");//编码<br style="word-wrap:break-word;">
131 android 判断是否为有效的网络url<br style="word-wrap:break-word;">
URLUtil.isNetworkUrl(strPath)<br style="word-wrap:break-word;">
132 android 创建垂直滚动条<br style="word-wrap:break-word;">
ScrollView scrollView = new ScrollView(this);<br style="word-wrap:break-word;">
133 android 创建水平滚动条<br style="word-wrap:break-word;">
HorizontalScrollView horizontalScrollView = new HorizontalScrollView(this);<br style="word-wrap:break-word;">
134 android 创建自动完成文本框<br style="word-wrap:break-word;">
AutoCompleteTextView autoCompleteTextView = new AutoCompleteTextView(this);<br style="word-wrap:break-word;">
135 android 创建地图控件MapView<br style="word-wrap:break-word;">
MapView mapView = new MapView(this);<br style="word-wrap:break-word;">
136 android 设置地图放大系数<br style="word-wrap:break-word;">
mapController = mapView.getController();<br style="word-wrap:break-word;">
mapController.setZoom(12);&nbsp;<br style="word-wrap:break-word;">
137 android layout增加和删除控件<br style="word-wrap:break-word;">
LinearLayout layout = new LinearLayout(this);<br style="word-wrap:break-word;">
Button button = new Button(this);<br style="word-wrap:break-word;">

Prev | Next
Pg.: 1 ... 3 4 5 6 7 8 9 10 11 12


Back to home | File page

Subscribe | Register | Login | N