学习笔记之——Android常用属性归纳
? ? ? ? 本篇博客僅作為個人學習筆記所用,各種Android常用屬性歸納長期更新,如有錯誤和建議還望指點~
1.控件透明度和半透明度:
半透明<Button?Android:background="#e0000000" ... />
透明<Button android:background="#00000000" ... />
顏色和不透明度 (alpha) 值以十六進制表示法表示。任何一種顏色的值范圍都是 0 到 255(00 到 ff)。對于 alpha,00 表示完全透明,ff 表示完全不透明。表達式順序是“aabbggrr”,其中aa=alpha(00 到 ff);bb=blue(00 到 ff);gg=green(00 到 ff);rr=red(00 到 ff)。例如,如果您希望對某疊加層應用不透明度為 50% 的藍色,則應指定以下值:7fff0000
View v = findViewById(R.id.content);//找到你要設透明背景的layout 的id?
v.getBackground().setAlpha(100);//0~255透明度值 ,0為完全透明,255為不透明
如果美工給你標注透明度多少,此時你不知道怎么變成16進制,可以參考下面的圖片,希望對你們有用
2.關于TextView、EditText屬性設置
EditText:
解決Andriod軟鍵盤出現把原來的布局給頂上去的方法:http://blog.csdn.net/xww810319/article/details/17397429
通過在AndroidManifest文件中activity標簽下添加android:windowSoftInputMode="adjustResize|stateHidden"屬性防止標題欄向上移動消失android:hint="請輸入數字!"//設置顯示在空間上的提示信息android:numeric="integer"//設置只能輸入整數,如果是小數則是:decimalandroid:singleLine="true"//設置單行輸入,一旦設置為true,則文字不會自動換行。android:gray="top"//多行中指針在第一行第一位置et.setSelection(et.length());//調整光標到最后一行android:autoText //自動拼寫幫助android:capitalize //首字母大寫android:digits //設置只接受某些數字android:singleLine //是否單行或者多行,回車是離開文本框還是文本框增加新行android:numeric //只接受數字android:password //密碼android:phoneNumber // 輸入電話號碼android:editable //是否可編輯android:autoLink=”all” //設置文本超鏈接樣式當點擊網址時,跳向該網址android:password="true"//設置只能輸入密碼android:textColor ="#ff8c00"//字體顏色android:textStyle="bold"//字體,bold,italic, bolditalicandroid:textSize="20dip"//大小android:capitalize ="characters"//以大寫字母寫android:textAlign="center"//EditText沒有這個屬性,但TextView有android:textColorHighlight="#cccccc"//被選中文字的底色,默認為藍色android:textColorHint="#ffff00"//設置提示信息文字的顏色,默認為灰色android:textScaleX="1.5"//控制字與字之間的間距android:typeface="monospace"//字型,normal,sans, serif, monospaceandroid:background="@null"//空間背景,這里沒有,指透明android:layout_weight="1"//權重在控制控 件顯示的大小時蠻有用的。android:textAppearance="?android:attr/textAppearanceLargeInverse"//文字外觀,這里引用的是系統自帶的一個外觀,?表示系統是否有這種外觀,否則使用默認的外觀。
(1)Android系統中TextView默認行間距比較窄,不美觀。
??? 我們可以設置每行的行間距,可以通過屬性android:lineSpacingExtra或android:lineSpacingMultiplier來做。
? ??在你要設置的TextView中加入如下代碼:
? ? ? ?(1)android:lineSpacingExtra?設置行間距,如”8dp”。
? ? ? ?(2)android:lineSpacingMultiplier?設置行間距的倍數,如”1.5″。
(2)?TextView在代碼中如果要修改drawableRight設置的圖片可以使 ? ? ? ? ? ?用setCompoundDrawables(Drawable?left,Drawable?top,Drawable?right,Drawable?bottom)
? ? ? ? ? Drawable可以通過?Drawable nav_up=getResources().getDrawable(R.drawable.button_nav_up);得到
? ? ? ? ?但是API提示,setCompoundDrawables()?調用的時候,Drawable對象必須調用setBounds(int left, int top, int right, int bottom)方法,于是我們 ? ? ? ? ?加一行代碼就可以了
[java]?view plaincopy(3)?通過textColorHint設置edittext提示信息的顏色 ? ?
(4)Android 設置EditText光標Cursor顏色及粗細在android的輸入框里,如果要修改光標的顏色及粗細步驟如下兩步即可搞定:
1.在資源文件drawable下新建一個光標控制color_cursor.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <size android:width="1dp" /> <solid android:color="#008000" /> </shape> 2.設置EditText:android:textCursorDrawable="@drawable/color_cursor"
3.關于ListView屬性設置
? ?(1)設置ListView分割線:dividerHight / divider
? ?(2)設置ListView不要右邊指示線:android:scrollbars="none"
? ? (3)android listview 取消頭部分割線
? ? ? ? ? ? ??
? ? ? ? ? listview分割線會在頭部、數據item、及根部的底部打印,如果要取消頭部分割線必須
? ? ? ? ? ? 先設置期方法
? ? ? ? ? ? addHeaderView(headView, null, true);
? ? ? ? ? ? addFooterView(footView, null, true);
? ? ? ? ? ? 注意:第三個參數必須為true,否則無效
? ? ? ? ? ? //顯示頭部出現分割線
? ? ? ? ? ? listview.setHeaderDividersEnabled(true);
? ? ? ? ? ? //禁止底部出現分割線?
? ? ? ? ? ? ?listview.setFooterDividersEnabled(false);
? ? ? ? ? ??Android:headerDividersEnabled="true"
? ? ? ? ? ? android:footerDividersEnabled="false"
? ? (4)任意加頭去頭,加腳去腳。
我們知道ListView在setAdapter之后再調用addHeader方法會拋出異常,而加腳有時管用,有時不管用。Android開發文檔中也明確指出ListView在setAdapter之后不應該再進行setHeader和setFooter方法。這明顯不能滿足我們的實際需求。
我的解決方案是:在setAdapter之前給ListView先加上一個空頭布局和空腳布局,布局高度設為wrap_content,這樣當頭或腳布局中沒有任何組件時,頭和腳是看不到的。當需要顯示頭和腳時,直接向頭和腳布局中添加要顯示的組件即可。即設置 ? ? ?組件.setVisibility(View.VISIBLE);或者組件.setVisibility(View.GONE);即可
(5)listview滑動監聽。
//listview滑動監聽mainListView.setOnScrollListener(new OnScrollListener() {@Overridepublic void onScrollStateChanged(AbsListView view, int scrollState) {switch (scrollState) { case OnScrollListener.SCROLL_STATE_IDLE: //停止break; case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL://正在滑動break; case OnScrollListener.SCROLL_STATE_FLING://開始滾動 break; } }@Overridepublic void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {}});
? ? ? (4)去掉expandablelistview左邊的圖標
?在xml文件里面寫死
?? ? ? ?<ExpandableListView
? ? ? ? ? ??Android:id="@+id/myExpandableListView"
? ? ? ? ? ? android:layout_width="fill_parent"
? ? ? ? ? ? android:layout_height="fill_parent"
? ? ? ? ? ? android:background="#ffffff" ? ? ? ? ?
? ??android:groupIndicator="@null" ? //去掉圖標
? ? ? ? ? ? android:cacheColorHint="#00000000" ?//解決點擊或者下來背景變黑的問題
? ? ? ? ? ? android:listSelector="#00000000" >
? ? ? ? </ExpandableListView> ?
?在程序里面動態改變
ExpandableListView?expandListView?=?(ExpandableListView)?findViewById(R.id.list);?
//設置?屬性?GroupIndicator?去掉默認向下的箭頭??
expandListView.setGroupIndicator(null);?
ExpandableListView去掉里頭的分割線代碼:
expandableList.setDivider(null);
xml:
Android:divider="@null"
或者
設置driverHeight="0dip"或者driver="透明的圖片",這是設置第一級菜單的分割線的,二級菜單ChildDriver="0dip"
4.關于其他功能屬性設置
? ? ?(1)xml中引入一個布局:
<include android:id="@+id/layout_float"layout="@layout/layout_usercenter_floathead"android:layout_width="match_parent"android:layout_height="<span style="font-family: Arial, Helvetica, sans-serif;">match_parent</span><span style="font-family: Arial, Helvetica, sans-serif;">"</span>/>? ? ? (2)drawable屬性:
? ? ? ? ? ? ??①設置控件選中時和默認時的圖片變化
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="@android:integer/config_shortAnimTime"><item android:state_pressed="true" android:drawable="@color/background_tab_pressed" /><item android:state_focused="true" android:drawable="@color/background_tab_pressed"/><item android:drawable="@android:color/transparent"/></selector>? ? ? ? ? ??②設置checkbox或者radiobutton等有點擊狀態的控件,點擊時圖片和默認圖片的顏色改變 <selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_checked="true" android:drawable="@drawable/corner_s"></item><item android:state_checked="false" android:drawable="@drawable/corner_n"></item> </selector>? ? ? ? ? ?③設置字體點擊時和默認時候的顏色改變 <selector xmlns:android="http://schemas.android.com/apk/res/android" ><item android:state_checked="true" android:color="#af0000"/> <item android:state_checked="false" android:color="#333333"/> </selector>? ? ? ? ??④設置角度、邊框顏色和邊框等屬性 <shape xmlns:android="http://schemas.android.com/apk/res/android" ><corners android:radius="20dp"/><solid android:color="#ffffff"/><stroke android:width="0.5dip" android:color="@color/color_d9" /> </shape>?設置虛線:
[html]?view plaincopy設置圓角:
[html]?view plaincopy[html]?view plaincopy
[html]?view plaincopy
5.Android布局自定義Shap圓形ImageView,可以單獨設置背景與圖片
一、圖片預覽:
一、實現功能:
需求要實現布局中為圓形圖片,圖片背景與圖標分開且合并到一個ImageView。
二、具體實現:
XML中布局中定義ImageView,關健設置兩個參數? Android:backgroup(設置背景),Android:src(設置ImageVIew中圖片),圓形圖片制作Drawable下定義xml shap樣式(solid-color,size-width\hight)
XML代碼如下:
<ImageView android:id="@+id/zhongjie" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/popwindow_zhongjie" android:scaleType="centerInside" android:src="@drawable/mark_caller_house_agent" />Drawable-樣式xml如下:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" android:useLevel="false"> <solid android:color="#66CC00"/> <size android:width="50dp" android:height="50dp"/> </shape>
6.android獲取設備屏幕大小的方法
// 獲取屏幕的默認分辨率Display display = getWindowManager().getDefaultDisplay();tv1.setText(display.getWidth() + "");tv2.setText(display.getHeight() + "");// 通過WindowManager獲取屏幕的大小DisplayMetrics dm = new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(dm);tv3.setText("width : " + dm.widthPixels);tv4.setText("heigth : " + dm.heightPixels);// 通過Resources獲取獲取屏幕的大小DisplayMetrics dm2 = getResources().getDisplayMetrics();tv5.setText("width2 : " + dm2.widthPixels);tv6.setText("heigth2 : " + dm2.heightPixels);
7.ImageView描邊
drawable屬性: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"android:useLevel="false" ><solid android:color="@color/color_bg_eee"/><size android:width="27dp"android:height="27dp"/> </shape>xml:
<ImageViewandroid:id="@+id/img_shuju_country"android:layout_width="27dp"android:layout_height="27dp"android:padding="1px"android:background="@drawable/shape_calendar_fragment_coutry_bg"android:scaleType="centerInside"android:src="@drawable/usa"android:layout_marginTop="7dp"android:layout_gravity="center_horizontal" />8.ScrollView
1.scrollview 自動定位到頂部 利用獲取焦點的方式定位到最頂部的組件或layoutrl_layout = (RelativeLayout) rootView.findViewById(R.id.rl_layout); rl_layout.setFocusable(true); rl_layout.setFocusableInTouchMode(true); rl_layout.requestFocus();
9.幾個經常用到的字符串的截取
string str="123abc456";
int i=3;
1 取字符串的前i個字符
???str=str.Substring(0,i); // or??str=str.Remove(i,str.Length-i);?
2 去掉字符串的前i個字符:
???str=str.Remove(0,i);? // or str=str.Substring(i);?
3 從右邊開始取i個字符:
??str=str.Substring(str.Length-i); // or str=str.Remove(0,str.Length-i);
4 從右邊開始去掉i個字符:
???str=str.Substring(0,str.Length-i); // or str=str.Remove(str.Length-i,i);
5 判斷字符串中是否有"abc" 有則去掉之
???using System.Text.RegularExpressions;
???string str = "123abc456";
???string a="abc";
?? Regex r = new? Regex(a);?
???Match m = r.Match(str);?
???if (m.Success)
???{
????//綠色部分與紫色部分取一種即可。
??????str=str.Replace(a,"");
??????Response.Write(str);???
????? string str1,str2;
????? str1=str.Substring(0,m.Index);
????? str2=str.Substring(m.Index+a.Length,str.Length-a.Length-m.Index);
??????Response.Write(str1+str2);?
???}
6 如果字符串中有"abc"則替換成"ABC"
???str=str.Replace("abc","ABC");
7.截取字符串
String str="asadsf shjasdhx";
? ? ? ? String[] split = str.split(" ");
BUG:Java.util.regex.PatternSyntaxException: Syntax error U_REGEX_RULE_SYNTAX near index 1
str =? bundle.getString("location").split("+");
改為
str =? bundle.getString("location").split("\\+");
或者
str =? bundle.getString("location").split("[+]");
8.獲取字符串資源
this.getResources().getString(R.string.setIP)
1、使用subString的方法去刪除
2、使用substring截取字符串
for (int t = 0; t < memberLen; t++) {
??????memTemp =? stafferMap.get(strMember[t]);
??????if(memTemp != null){
???????memberNames += memTemp + ",";
??????}
?????}
以上的代碼,拼接的字符串會多一個“,”,比如:"str1,str2,str3,",要去除str3后的逗號,可用如下方法:
?????
?????memberNames = memberNames.substring(0,memberNames.length()-1);
?
比如當Team1=test ? ', 'U1-Team ? ', 'V-Team ? ', '時?
如何改成:?
Team1= 'test ? ', 'U1-Team ? ', 'V-Team ? '
可用:
Team1 ? = ? " ' " ? + ? Team1.Substring(0, ? Team1.Length ? - ? 2);
2、
9.解決ScrollView會自動滑動到非頂部bug
img_comments_ad = (ImageView) findViewById(R.id.img_comments_ad);//位于ScrollView最頂部的控件//解決ScrollView會自動滑動到非頂部bug
img_comments_ad.setFocusable(true);
img_comments_ad.setFocusableInTouchMode(true);
img_comments_ad.requestFocus();
10.判斷網絡是否連接
public class ConnectionUtils {public static boolean isWIFI(Context context){if (isConnected(context)){ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo info = cm.getActiveNetworkInfo();int type = info.getType();if (ConnectivityManager.TYPE_WIFI == type){return true; }}return false;}public static boolean isMobile(Context context){if (isConnected(context)){ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo info = cm.getActiveNetworkInfo();int type = info.getType();if (ConnectivityManager.TYPE_MOBILE == type){return true; }}return false;}public static boolean isConnected(Context context){ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo info = cm.getActiveNetworkInfo();if (info == null){return false;}boolean available = info.isAvailable();return available;} }使用: if (!ConnectionUtils.isConnected(getContext())){ //網絡無連接狀態 }else{//網絡連接狀態 }11.獲取當前時間
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date curDate = new Date(System.currentTimeMillis());//獲取當前時間 String currenTime = format.format(curDate);clickDay = Integer.parseInt(currenTime.split("-")[2]);//String轉成int當前日期 Calendar c = Calendar.getInstance(); String mWeek = String.valueOf(c.get(Calendar.DAY_OF_WEEK));//獲取周 if ("1".equals(mWeek)) {mWeek = "日";} else if ("2".equals(mWeek)) {mWeek = "一";} else if ("3".equals(mWeek)) {mWeek = "二";} else if ("4".equals(mWeek)) {mWeek = "三";} else if ("5".equals(mWeek)) {mWeek = "四";} else if ("6".equals(mWeek)) {mWeek = "五";} else if ("7".equals(mWeek)) {mWeek = "六";}12.動態添加布局、動態設置relativelayout布局高度
LinearLayout ll = (LinearLayout) findViewById(R.id.ll); LayoutInflater inflater = getLayoutInflater(); View child = inflater.inflate(R.layout.layout_add, null); ll.addView(child); Demo下載:http://download.csdn.net/detail/lxlyhm/9712684設置RelativeLayout布局高度: RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams)rl_downup_all.getLayoutParams();linearParams.height = 800;rl_downup_all.setLayoutParams(linearParams);
2、動態的獲取和設置ImageView的寬度和高度
LayoutParams para; para = image.getLayoutParams(); Log.d(TAG, "layout height0: " + para.height); Log.d(TAG, "layout width0: " + para.width); para.height = 300; para.width = 300; image.setLayoutParams(para); Log.d(TAG, "layout height: " + para.height); Log.d(TAG, "layout width: " + para.width);
13.代碼調用value色值
tv_header_title.setTextColor(getResources().getColor(R.color.common_bg_color));附.色值 <color name="white">#ffffff</color><!--白色 --> <color name="ivory">#fffff0</color><!--象牙色 --> <color name="lightyellow">#ffffe0</color><!--亮黃色 --> <color name="yellow">#ffff00</color><!--黃色 --> <color name="snow">#fffafa</color><!--雪白色 --> <color name="floralwhite">#fffaf0</color><!--花白色 --> <color name="lemonchiffon">#fffacd</color><!--檸檬綢色 --> <color name="cornsilk">#fff8dc</color><!--米綢色 --> <color name="seaShell">#fff5ee</color><!--海貝色 --> <color name="lavenderblush">#fff0f5</color><!--淡紫紅 --> <color name="papayawhip">#ffefd5</color><!--番木色 --> <color name="blanchedalmond">#ffebcd</color><!--白杏色 --> <color name="mistyrose">#ffe4e1</color><!--淺玫瑰色 --> <color name="bisque">#ffe4c4</color><!--桔黃色 --> <color name="moccasin">#ffe4b5</color><!--鹿皮色 --> <color name="navajowhite">#ffdead</color><!--納瓦白 --> <color name="peachpuff">#ffdab9</color><!--桃色 --> <color name="gold">#ffd700</color><!--金色 --> <color name="pink">#ffc0cb</color><!--粉紅色 --> <color name="lightpink">#ffb6c1</color><!--亮粉紅色 --> <color name="orange">#ffa500</color><!--橙色 --> <color name="lightsalmon">#ffa07a</color><!--亮肉色 --> <color name="darkorange">#ff8c00</color><!--暗桔黃色 --> <color name="coral">#ff7f50</color><!--珊瑚色 --> <color name="hotpink">#ff69b4</color><!--熱粉紅色 --> <color name="tomato">#ff6347</color><!--西紅柿色 --> <color name="orangered">#ff4500</color><!--紅橙色 --> <color name="deeppink">#ff1493</color><!--深粉紅色 --> <color name="fuchsia">#ff00ff</color><!--紫紅色 --> <color name="magenta">#ff00ff</color><!--紅紫色 --> <color name="red">#ff0000</color><!--紅色 --> <color name="oldlace">#fdf5e6</color><!--老花色 --> <color name="lightgoldenrodyellow">#fafad2</color><!--亮金黃色 --> <color name="linen">#faf0e6</color><!--亞麻色 --> <color name="antiquewhite">#faebd7</color><!--古董白 --> <color name="salmon">#fa8072</color><!--鮮肉色 --> <color name="ghostwhite">#f8f8ff</color><!--幽靈白 --> <color name="mintcream">#f5fffa</color><!--薄荷色 --> <color name="whitesmoke">#f5f5f5</color><!--煙白色 --> <color name="beige">#f5f5dc</color><!--米色 --> <color name="wheat">#f5deb3</color><!--淺黃色 --> <color name="sandybrown">#f4a460</color><!--沙褐色 --> <color name="azure">#f0ffff</color><!--天藍色 --> <color name="honeydew">#f0fff0</color><!--蜜色 --> <color name="aliceblue">#f0f8ff</color><!--艾利斯蘭 --> <color name="khaki">#f0e68c</color><!--黃褐色 --> <color name="lightcoral">#f08080</color><!--亮珊瑚色 --> <color name="palegoldenrod">#eee8aa</color><!--蒼麒麟色 --> <color name="violet">#ee82ee</color><!--紫羅蘭色 --> <color name="darksalmon">#e9967a</color><!--暗肉色 --> <color name="lavender">#e6e6fa</color><!--淡紫色 --> <color name="lightcyan">#e0ffff</color><!--亮青色 --> <color name="burlywood">#deb887</color><!--實木色 --> <color name="plum">#dda0dd</color><!--洋李色 --> <color name="gainsboro">#dcdcdc</color><!--淡灰色 --> <color name="crimson">#dc143c</color><!--暗深紅色 --> <color name="palevioletred">#db7093</color><!--蒼紫羅蘭色 --> <color name="goldenrod">#daa520</color><!--金麒麟色 --> <color name="orchid">#da70d6</color><!--淡紫色 --> <color name="thistle">#d8bfd8</color><!--薊色 --> <color name="lightgray">#d3d3d3</color><!--亮灰色 --> <color name="lightgrey">#d3d3d3</color><!--亮灰色 --> <color name="tan">#d2b48c</color><!--茶色 --> <color name="chocolate">#d2691e</color><!--巧可力色 --> <color name="peru">#cd853f</color><!--秘魯色 --> <color name="indianred">#cd5c5c</color><!--印第安紅 --> <color name="mediumvioletred">#c71585</color><!--中紫羅蘭色 --> <color name="silver">#c0c0c0</color><!--銀色 --> <color name="darkkhaki">#bdb76b</color><!--暗黃褐色 --> <color name="rosybrown">#bc8f8f</color><!--褐玫瑰紅 --> <color name="mediumorchid">#ba55d3</color><!--中粉紫色 --> <color name="darkgoldenrod">#b8860b</color><!--暗金黃色 --> <color name="firebrick">#b22222</color><!--火磚色 --> <color name="powderblue">#b0e0e6</color><!--粉藍色 --> <color name="lightsteelblue">#b0c4de</color><!--亮鋼蘭色 --> <color name="paleturquoise">#afeeee</color><!--蒼寶石綠 --> <color name="greenyellow">#adff2f</color><!--黃綠色 --> <color name="lightblue">#add8e6</color><!--亮藍色 --> <color name="darkgray">#a9a9a9</color><!--暗灰色 --> <color name="darkgrey">#a9a9a9</color><!--暗灰色 --> <color name="brown">#a52a2a</color><!--褐色 --> <color name="sienna">#a0522d</color><!--赭色 --> <color name="darkorchid">#9932cc</color><!--暗紫色 --> <color name="palegreen">#98fb98</color><!--蒼綠色 --> <color name="darkviolet">#9400d3</color><!--暗紫羅蘭色 --> <color name="mediumpurple">#9370db</color><!--中紫色 --> <color name="lightgreen">#90ee90</color><!--亮綠色 --> <color name="darkseagreen">#8fbc8f</color><!--暗海蘭色 --> <color name="saddlebrown">#8b4513</color><!--重褐色 --> <color name="darkmagenta">#8b008b</color><!--暗洋紅 --> <color name="darkred">#8b0000</color><!--暗紅色 --> <color name="blueviolet">#8a2be2</color><!--紫羅蘭藍色 --> <color name="lightskyblue">#87cefa</color><!--亮天藍色 --> <color name="skyblue">#87ceeb</color><!--天藍色 --> <color name="gray">#808080</color><!--灰色 --> <color name="grey">#808080</color><!--灰色 --> <color name="olive">#808000</color><!--橄欖色 --> <color name="purple">#800080</color><!--紫色 --> <color name="maroon">#800000</color><!--粟色 --> <color name="aquamarine">#7fffd4</color><!--碧綠色 --> <color name="chartreuse">#7fff00</color><!--黃綠色 --> <color name="lawngreen">#7cfc00</color><!--草綠色 --> <color name="mediumslateblue">#7b68ee</color><!--中暗藍色 --> <color name="lightslategray">#778899</color><!--亮藍灰 --> <color name="lightslategrey">#778899</color><!--亮藍灰 --> <color name="slategray">#708090</color><!--灰石色 --> <color name="slategrey">#708090</color><!--灰石色 --> <color name="olivedrab">#6b8e23</color><!--深綠褐色 --> <color name="slateblue">#6a5acd</color><!--石藍色 --> <color name="dimgray">#696969</color><!--暗灰色 --> <color name="dimgrey">#696969</color><!--暗灰色 --> <color name="mediumaquamarine">#66cdaa</color><!--中綠色 --> <color name="cornflowerblue">#6495ed</color><!--菊蘭色 --> <color name="cadetblue">#5f9ea0</color><!--軍蘭色 --> <color name="darkolivegreen">#556b2f</color><!--暗橄欖綠 --> <color name="indigo">#4b0082</color><!--靛青色 --> <color name="mediumturquoise">#48d1cc</color><!--中綠寶石 --> <color name="darkslateblue">#483d8b</color><!--暗灰藍色 --> <color name="steelblue">#4682b4</color><!--鋼蘭色 --> <color name="royalblue">#4169e1</color><!--皇家藍 --> <color name="turquoise">#40e0d0</color><!--青綠色 --> <color name="mediumseagreen">#3cb371</color><!--中海藍 --> <color name="limegreen">#32cd32</color><!--橙綠色 --> <color name="darkslategray">#2f4f4f</color><!--暗瓦灰色 --> <color name="darkslategrey">#2f4f4f</color><!--暗瓦灰色 --> <color name="seagreen">#2e8b57</color><!--海綠色 --> <color name="forestgreen">#228b22</color><!--森林綠 --> <color name="lightseagreen">#20b2aa</color><!--亮海藍色 --> <color name="dodgerblue">#1e90ff</color><!--閃蘭色 --> <color name="midnightblue">#191970</color><!--中灰蘭色 --> <color name="aqua">#00ffff</color><!--淺綠色 --> <color name="cyan">#00ffff</color><!--青色 --> <color name="springgreen">#00ff7f</color><!--春綠色 --> <color name="lime">#00ff00</color><!--酸橙色 --> <color name="mediumspringgreen">#00fa9a</color><!--中春綠色 --> <color name="darkturquoise">#00ced1</color><!--暗寶石綠 --> <color name="deepskyblue">#00bfff</color><!--深天藍色 --> <color name="darkcyan">#008b8b</color><!--暗青色 --> <color name="teal">#008080</color><!--水鴨色 --> <color name="green">#008000</color><!--綠色 --> <color name="darkgreen">#006400</color><!--暗綠色 --> <color name="blue">#0000ff</color><!--藍色 --> <color name="mediumblue">#0000cd</color><!--中蘭色 --> <color name="darkblue">#00008b</color><!--暗藍色 --> <color name="navy">#000080</color><!--海軍色 --> <color name="black">#000000</color><!--黑色 --> <color name="transparent">#0000</color><!-- 透明 --><color name="transparent2">#8000</color><!-- 透明 -->
軟鍵盤頂住:xml清單配置這句話即可 android:windowSoftInputMode="adjustPan|stateHidden"
?
軟鍵盤彈出布局與edittext一起上移
Androidmanifest的activity設置成
時間轉換為時間戳:
/* * 將時間轉換為時間戳*/ public static String dateToStamp(String s) throws ParseException{String res;SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date = simpleDateFormat.parse(s);long ts = date.getTime();res = String.valueOf(ts);return res;}時間戳轉換為時間: /* * 將時間戳轉換為時間*/public static String stampToDate(String s){String res;SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");long lt = new Long(s);Date date = new Date(lt);res = simpleDateFormat.format(date);return res;}
BaseActivity.java中打印log知曉當前開啟的是哪一個活動: Log.d(“BaseActivity”, getClass().getSimpleName());
給button加圓角
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- 填充的顏色 --> <solid android:color="#ff000000" /> <!-- 設置矩形的四個角為弧形 --> <!-- android:radius 弧形的半徑 --> <corners android:radius="7dip" /> </shape>
layout中給button加上background屬性
Android:background="@drawable/round_corner_bg"
1.RadioButton?
去掉默認的圓圈樣式:mButtonleft.setButtonDrawable(Android.R.color.transparent);
? ? 在xml內:android:button="@null";
2. 獲取windowmager的方法:
WindowManager m = (WindowManager) getView().getContext().getSystemService(getView().getContext().WINDOW_SERVICE);3.如果view包含parent的情況下不能添加進去到布局里面,先獲取view的parent再移除:
ViewGroup g=(ViewGroup) v.getParent(); g.removeView(v);;4. 同一個view只能addview一次到布局里面,否則報已經有parent 的錯誤。
5. 用代碼控制view 與其他view的距離
View.setTranslationX //Sets the horizontal location of this view relative to its left position
6.設置背景為透明:顏色設置為#00000000;
7.measure
只有View類中才有這個方法,也就是說所有的View,像LinearLayout、Button這些控件的measure方法都是從View繼承的,onMeasure方法才是真正的測量控件大小的方法,是由View的子類實現的,onMeasure是在measure方法中調用的
8.內存
棧內存一般用于存儲基本類型數據以及對象的引用,堆內存一般存儲對象的本體。棧的速度比較快,是快速存儲。棧有一個很重要的特殊性,就是存在棧中的數據可以共享。比如int a=3;?首先它會在棧中創建一個變量為a的引用,然后查找有沒有字面值為3的地址,沒找到,就開辟一個存放3這個字面值的地址,然后將a指向3的地址。記住只要是用new()來新建對象的,都會在堆中創建,而且其字符串是單獨存值的,即使與棧中的數據相同,也不會與棧中的數據共享。所以?String str = " abc" ;很有可能只是指向共享的數據而沒有創建新對象,而已new String("abc");就一定會創建新對象,而且是在堆里面創建對象
使用String str = " abc" ;的方式,可以在一定程度上提高程序的運行速度,因為JVM會自動根據棧中數據的實際情況來決定是否有必要創建新對象。而對于String str = new String(" abc" );的代碼,則一概在堆中創建新對象,而不管其字符串值是否相等,是否有必要創建新對象,從而加重了程序的負擔。
9.比較
? ?當比較包裝類里面的數值是否相等時,用equals()方法;當測試兩個包裝類的引用是否指向同一個對象時,用==。
?1.基本數據類型,也稱原始數據類型。byte,short,char,int,long,float,double,boolean?
? 他們之間的比較,應用雙等號(==),比較的是他們的值。??
?2.復合數據類型(類)?
? 當他們用(==)進行比較的時候,比較的是他們在內存中的存放地址,所以,除非是同一個new出來的對象,他們的比較后 ?的結果為true,否則比較后結果為false。?Java當中所有的類都是繼承于Object這個基類的,在Object中的基類中定義了 一個equals的方法,這個方法的初始行為是比較對象的內存地 址,但在一些類庫當中這個方法被覆蓋掉了,如String,Integer,Date在這些類當中equals有其自身的實現,而不再是比較類在堆內存中的存放地址了。
10.退出activity
退出時不把Activity殺死,下次進來還是會加載原來那個Activity而不會重新加載。
? ??
11.一鍵清理后靜態變量會初始化。
? ?
12.Imageview 加載幀動畫
[java]?view plaincopy print?13.代碼控制View之間的間距;
[java]?view plaincopy print?
14.RadioButton?
設置layoutParam 使用radiogroup
[java]?view plaincopy print?
15.獲取屏幕大小的方法,得到一個屏幕尺寸的三種方法如下:
// 通過WindowManager獲取
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
// 通過Resources獲取
DisplayMetrics dm2 = getResources().getDisplayMetrics();
// 獲取屏幕的默認分辨率
Display display = getWindowManager().getDefaultDisplay();
System.out.println("width-display :" + display.getWidth());
System.out.println("heigth-display :" + display.getHeight());
得到一個屏幕尺寸的三種方法如下:
// 通過WindowManager獲取
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
// 通過Resources獲取
DisplayMetrics dm2 = getResources().getDisplayMetrics();
// 獲取屏幕的默認分辨率
Display display = getWindowManager().getDefaultDisplay();
System.out.println("width-display :" + display.getWidth());
System.out.println("heigth-display :" + display.getHeight());
在安卓4.2系統中,使用方法一得到了正確的屏幕尺寸值,而使用方法二和三得到的值全部為零。原因不祥。其中方法三中的display.getWidth()和display.getHeight()已被棄用。
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);//display = getWindowManager().getDefaultDisplay(); display.getMetrics(dm)(把屏幕尺寸信息賦值給DisplayMetrics dm);
width = dm.widthPixels;
height = dm.heightPixels;
xdpi = dm.xdpi;
ydpi = dm.ydpi;
density = dm.densityDpi;
fdensity = dm.density;
查詢log,得到各值如下:
D/Lichking(22643): -----------widthpixels---540
D/Lichking(22643): -----------heightpixels---960
D/Lichking(22643): -----------xdpi---244.92857
D/Lichking(22643): -----------ydpi---246.30302
D/Lichking(22643): -----------density---240
D/Lichking(22643): -----------fdensity---1.5
另提一點,我們通常所指的屏幕上的int尺寸是像素單位,比如我用getHitRect()得到控件的矩形坐標的值即使和像素尺寸相匹配的。
DisplayMetrics和Display的關系。
Display指代顯示區域這個對象,它可能是真實的物理屏幕,也可能僅指應用程序的顯示區域,比如在非全屏Activity里,系統因為有狀態欄,因此顯示區域要比物理屏幕要小。DisplayMetrics里封裝了顯示區域的各種屬性值。查看源碼發現,在DisplayMetrics對各個屬性值的注釋都說明為真實的物理尺寸。而且也發現display.getMetrics(dm)這一函數基本在應用在獲取真實屏幕尺寸的時候。記住這一點即好。
另外xdpi不是指屏幕寬度上以dp為單位的大小。以dp為單位的屏幕寬度需用計算公式:dpWidth = WidthPixels / fdensity = 540 / 1.5 = 360
16.shdaer
Android中提供了Shader類專門用來渲染圖像以及一些幾何圖形,Shader下面包括幾個直接子類,分別是BitmapShader、 ComposeShader、LinearGradient、RadialGradient、SweepGradient。 BitmapShader主要用來渲染圖像,LinearGradient 用來進行梯度渲染,RadialGradient 用來進行環形渲染,SweepGradient 用來進行梯度渲染,ComposeShader則是一個 混合渲染,可以和其它幾個子類組合起來使用。
17.WeakReference
弱引用,用于觀察某對象什么時候會被垃圾收集的執行緒清除,你必須要用一個 reference 記住它,以便隨時觀察,但是卻因此造成此對象的 reference 數目一直無法為零, 使得對象無法被清除。這時候可以使用 Weak Reference 這個類。如果你希望能隨時取得某對象的信息,但又不想影響此對象的垃圾收集,那么你應該用 Weak Reference 來記住此對象,而不是使用一般的 reference。
18. Soft Reference
Soft Reference 雖然和 Weak Reference 很類似,但是用途卻不同。 被 Soft Reference 指到的對象,即使沒有任何 Direct Reference,也不會被清除。一直要到 JVM 內存不足時且 沒有 Direct Reference 時才會清除,SoftReference 是用來設計 object-cache 之用的。如此一來 SoftReference 不但可以把對象 cache 起來(參考http://blog.csdn.net/yuzhiboyi/article/details/7775963)
19.Assert
斷言是一個調試程序時經常使用的宏,在程序運行時它計算括號內的表達式,如果表達式為FALSE (0), 程序將報告錯誤,并終止執行。如果表達式不為0,則繼續執行后面的語句。這個宏通常原來判斷程序中是否出現了明顯非法的數據,如果出現了終止程序以免導致嚴重后果,同時也便于查找錯誤
20.textview.settextsize(float size)
源碼可以看到,最終set進去設置的是px單位,它會將轉為sp,所以使用時應該使用sp,轉為px后set進去:
21.listview 的item去掉默認選中樣式:
mListView.setSelector(new ColorDrawable(Color.TRANSPARENT));
22.Application單例問題:
系統只會創建一個application,所以以下方式創建單例application是錯誤的,雖然獲取context 不會報錯,可是獲取context的服務會出現空指針:
[java]?view plaincopy print?
應該這樣使用:
[java]?view plaincopy print?
23.Liteview item
具有緩存機制,會緩存第一頁的view,也就是說第一頁的item是null,第二頁不是null,因此可以利用holder來快速找打view,但是如果需要listview不同位置顯示不一樣的話就不可以利用緩存了,緩存機制應該是每個view都是一樣的,只是數據不同,但是如果不同位置的view不一樣的話就沒法利用緩存,只能通過不斷的創建view方式。
24.viewpaer的問題一般是出現在緩存問題上,特別要注意。
25.與動畫使用放在一起的操作,優化方式有:通過動畫監聽,動畫結束后才做相關操作。
26.relativelayout代碼設置子view居中
[java]?view plaincopy print?27.android java.lang.NoSuchFieldError: R$id.xxx異常
第一種情況 參考自http://www.shangxueba.com/jingyan/1856083.html
將引用的自定義控件的xml文件中的最外層布局上面添加xmlns:sat=“http://schemas.android.com/apk/res/控件所在位置的包名”可是在運行時就會報java.lang.NoSuchFieldError:包.R$id.xxx錯。同時還會出現no resource identifier found for attribute 的錯誤。
將xmlns:sat=“http://schemas.android.com/apk/res/控件所在位置的包名”更改為
http://schemas.android.com/apk/res-auto 就不會報錯了
第二種 參考:http://www.hankcs.com/program/mobiledev/e-androidruntime-fatal-exception-main-java-lang-nosuchfielderror.html
這個問題是由于主項目覆蓋了庫項目的xml所致,如果主項目中的某個xml里定義了一個跟庫項目中的xml同名的xml,那么庫中的xml將會被覆蓋。這里的覆蓋意思是,編譯后只有主項目中的xml以及R.id,完全沒有庫項目的影子。所以才會有NoSuchFieldError的錯誤。
這個錯誤不會在編譯的時候提示,算得上一個陷阱了。
解決方法很簡單,刪除主項目中的xml,整個項目只保留一份xml即可
28.設置relativelayout 子控件劇中
[java]?view plaincopy print?
29.List調用toString方法
import org.apache.commons.lang.StringUtils; public class Test { public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("1"); list.add("2"); list.add("3"); System.out.println(list.toString()); System.out.println(StringUtils.strip(list.toString(),"[]")); } }
打印內容: [1, 2, 3] 1, 2, 3
30.StringUtils工具類的常用方法
下面分別對一些常用方法做簡要介紹:
1.?public static boolean isEmpty(String str)?
?? 判斷某字符串是否為空,為空的標準是?str==null?或?str.length()==0?
?? 下面是?StringUtils?判斷是否為空的示例:
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true?
StringUtils.isEmpty(" ") = false?//注意在?StringUtils?中空格作非空處理
StringUtils.isEmpty("?? ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
?
2.?public static boolean isNotEmpty(String str)?
?? 判斷某字符串是否非空,等于?!isEmpty(String str)?
?? 下面是示例:
????? StringUtils.isNotEmpty(null) = false
????? StringUtils.isNotEmpty("") = false
????? StringUtils.isNotEmpty(" ") = true
????? StringUtils.isNotEmpty("???????? ") = true
????? StringUtils.isNotEmpty("bob") = true
????? StringUtils.isNotEmpty(" bob ") = true?
3.?public static boolean isBlank(String str)?
?? 判斷某字符串是否為空或長度為0或由空白符(whitespace)?構成
?? 下面是示例:
????? StringUtils.isBlank(null) = true
????? StringUtils.isBlank("") = true
????? StringUtils.isBlank(" ") = true
????? StringUtils.isBlank("??????? ") = true
????? StringUtils.isBlank("\t \n \f \r") = true?? //對于制表符、換行符、換頁符和回車符
????? StringUtils.isBlank()?? //均識為空白符
????? StringUtils.isBlank("\b") = false?? //"\b"為單詞邊界符
????? StringUtils.isBlank("bob") = false
????? StringUtils.isBlank(" bob ") = false?
4.?public static boolean isNotBlank(String str)?
?? 判斷某字符串是否不為空且長度不為0且不由空白符(whitespace)?構成,等于?!isBlank(String str)?
?? 下面是示例:
??????StringUtils.isNotBlank(null) = false
??????StringUtils.isNotBlank("") = false
??????StringUtils.isNotBlank(" ") = false
??????StringUtils.isNotBlank("???????? ") = false
??????StringUtils.isNotBlank("\t \n \f \r") = false
??????StringUtils.isNotBlank("\b") = true
??????StringUtils.isNotBlank("bob") = true
??????StringUtils.isNotBlank(" bob ") = true?
5.?public static String trim(String str)?
?? 去掉字符串兩端的控制符(control characters, char <= 32)?, 如果輸入為?null?則返回null?
?? 下面是示例:
??????StringUtils.trim(null) = null
??????StringUtils.trim("") = ""
??????StringUtils.trim(" ") = ""
??????StringUtils.trim("? \b \t \n \f \r??? ") = ""
??????StringUtils.trim("???? \n\tss?? \b") = "ss"
??????StringUtils.trim(" d?? d dd???? ") = "d?? d dd"
??????StringUtils.trim("dd???? ") = "dd"
??????StringUtils.trim("???? dd?????? ") = "dd"?
6.?public static String trimToNull(String str)?
?? 去掉字符串兩端的控制符(control characters, char <= 32)?,如果變為?null?或"",則返回?null?
?? 下面是示例:
??????StringUtils.trimToNull(null) = null
??????StringUtils.trimToNull("") = null
??????StringUtils.trimToNull(" ") = null
??????StringUtils.trimToNull("???? \b \t \n \f \r??? ") = null
??????StringUtils.trimToNull("???? \n\tss?? \b") = "ss"
??????StringUtils.trimToNull(" d?? d dd???? ") = "d?? d dd"
??????StringUtils.trimToNull("dd???? ") = "dd"
??????StringUtils.trimToNull("???? dd?????? ") = "dd"?
7.?public static String trimToEmpty(String str)?
?? 去掉字符串兩端的控制符(control characters, char <= 32)?,如果變為?null?或?""?,則返回?""?
?? 下面是示例:
??????StringUtils.trimToEmpty(null) = ""
??????StringUtils.trimToEmpty("") = ""
??????StringUtils.trimToEmpty(" ") = ""
??????StringUtils.trimToEmpty("???? \b \t \n \f \r??? ") = ""
??????StringUtils.trimToEmpty("???? \n\tss?? \b") = "ss"
??????StringUtils.trimToEmpty(" d?? d dd???? ") = "d?? d dd"
??????StringUtils.trimToEmpty("dd???? ") = "dd"
??????StringUtils.trimToEmpty("???? dd?????? ") = "dd"?
8.?public static String strip(String str)?
?? 去掉字符串兩端的空白符(whitespace)?,如果輸入為?null?則返回?null?
?? 下面是示例(注意和?trim()?的區別):
??????StringUtils.strip(null) = null
??????StringUtils.strip("") = ""
??????StringUtils.strip(" ") = ""
??????StringUtils.strip("???? \b \t \n \f \r??? ") = "\b"
??????StringUtils.strip("???? \n\tss?? \b") = "ss?? \b"
??????StringUtils.strip(" d?? d dd???? ") = "d?? d dd"
??????StringUtils.strip("dd???? ") = "dd"
??????StringUtils.strip("???? dd?????? ") = "dd"?
9.?public static String stripToNull(String str)?
?? 去掉字符串兩端的空白符(whitespace)?,如果變為?null?或"",則返回?null?
?? 下面是示例(注意和?trimToNull()?的區別):
??????StringUtils.stripToNull(null) = null
??????StringUtils.stripToNull("") = null
??????StringUtils.stripToNull(" ") = null
??????StringUtils.stripToNull("???? \b \t \n \f \r??? ") = "\b"
??????StringUtils.stripToNull("???? \n\tss?? \b") = "ss?? \b"
??????StringUtils.stripToNull(" d?? d dd???? ") = "d?? d dd"
??????StringUtils.stripToNull("dd???? ") = "dd"
??????StringUtils.stripToNull("???? dd?????? ") = "dd"?
10.?public static String stripToEmpty(String str)?
??? 去掉字符串兩端的空白符(whitespace)?,如果變為?null?或""?,則返回""?
??? 下面是示例(注意和?trimToEmpty()?的區別):
??????StringUtils.stripToNull(null) = ""
??????StringUtils.stripToNull("") = ""
??????StringUtils.stripToNull(" ") = ""
??????StringUtils.stripToNull("???? \b \t \n \f \r??? ") = "\b"
??????StringUtils.stripToNull("???? \n\tss?? \b") = "ss?? \b"
??????StringUtils.stripToNull(" d?? d dd???? ") = "d?? d dd"
??????StringUtils.stripToNull("dd???? ") = "dd"
??????StringUtils.stripToNull("???? dd?????? ") = "dd"?
以下方法只介紹其功能,不再舉例:
11.?public static String strip(String str, String stripChars)?
?? 去掉?str?兩端的在?stripChars?中的字符。
?? 如果?str?為?null?或等于""?,則返回它本身;
?? 如果?stripChars?為?null?或""?,則返回?strip(String str)?。
12.?public static String stripStart(String str, String stripChars)?
??? 和11相似,去掉?str?前端的在?stripChars?中的字符。
13.?public static String stripEnd(String str, String stripChars)?
??? 和11相似,去掉?str?末端的在?stripChars?中的字符。
14.?public static String[] stripAll(String[] strs)?
??? 對字符串數組中的每個字符串進行?strip(String str)?,然后返回。
??? 如果?strs?為?null?或?strs?長度為0,則返回?strs?本身
15.?public static String[] stripAll(String[] strs, String stripChars)?
??? 對字符串數組中的每個字符串進行?strip(String str, String stripChars)?,然后返回。
??? 如果?strs?為?null?或?strs?長度為0,則返回?strs?本身
16.?public static boolean equals(String str1, String str2)?
??? 比較兩個字符串是否相等,如果兩個均為空則也認為相等。
17.?public static boolean equalsIgnoreCase(String str1, String str2)?
??? 比較兩個字符串是否相等,不區分大小寫,如果兩個均為空則也認為相等。
18.?public static int indexOf(String str, char searchChar)?
??? 返回字符 searchChar 在字符串?str?中第一次出現的位置。
??? 如果?searchChar?沒有在?str?中出現則返回-1,
??? 如果?str?為?null?或?""?,則也返回-1
19.?public static int indexOf(String str, char searchChar, int startPos)?
??? 返回字符?searchChar?從?startPos?開始在字符串?str?中第一次出現的位置。
??? 如果從?startPos?開始?searchChar?沒有在?str?中出現則返回-1,
??? 如果?str?為?null?或?""?,則也返回-1
20.?public static int indexOf(String str, String searchStr)?
??? 返回字符串?searchStr?在字符串?str?中第一次出現的位置。
??? 如果?str?為?null?或?searchStr?為?null?則返回-1,
??? 如果?searchStr?為?""?,且?str?為不為?null?,則返回0,
??? 如果?searchStr?不在?str?中,則返回-1
21.?public static int ordinalIndexOf(String str, String searchStr, int ordinal)?
??? 返回字符串?searchStr?在字符串?str?中第?ordinal?次出現的位置。
??? 如果?str=null?或?searchStr=null?或?ordinal<=0?則返回-1
??? 舉例(*代表任意字符串):
??????StringUtils.ordinalIndexOf(null, *, *) = -1
??????StringUtils.ordinalIndexOf(*, null, *) = -1
??????StringUtils.ordinalIndexOf("", "", *) = 0
??????StringUtils.ordinalIndexOf("aabaabaa", "a", 1) = 0
??????StringUtils.ordinalIndexOf("aabaabaa", "a", 2) = 1
??????StringUtils.ordinalIndexOf("aabaabaa", "b", 1) = 2
??????StringUtils.ordinalIndexOf("aabaabaa", "b", 2) = 5
??????StringUtils.ordinalIndexOf("aabaabaa", "ab", 1) = 1
??????StringUtils.ordinalIndexOf("aabaabaa", "ab", 2) = 4
??????StringUtils.ordinalIndexOf("aabaabaa", "bc", 1) = -1
??????StringUtils.ordinalIndexOf("aabaabaa", "", 1) = 0
??????StringUtils.ordinalIndexOf("aabaabaa", "", 2) = 0?
22.?public static int indexOf(String str, String searchStr, int startPos)?
??? 返回字符串?searchStr?從?startPos?開始在字符串?str?中第一次出現的位置。
??? 舉例(*代表任意字符串):
??????StringUtils.indexOf(null, *, *) = -1
??????StringUtils.indexOf(*, null, *) = -1
??????StringUtils.indexOf("", "", 0) = 0
??????StringUtils.indexOf("aabaabaa", "a", 0) = 0
??????StringUtils.indexOf("aabaabaa", "b", 0) = 2
??????StringUtils.indexOf("aabaabaa", "ab", 0) = 1
??????StringUtils.indexOf("aabaabaa", "b", 3) = 5
??????StringUtils.indexOf("aabaabaa", "b", 9) = -1
??????StringUtils.indexOf("aabaabaa", "b", -1) = 2
??????StringUtils.indexOf("aabaabaa", "", 2) = 2
??????StringUtils.indexOf("abc", "", 9) = 3?
23.?public static int lastIndexOf(String str, char searchChar)?
??? 基本原理同18
24.?public static int lastIndexOf(String str, char searchChar, int startPos)?
??? 基本原理同19
25.?public static int lastIndexOf(String str, String searchStr)?
??? 基本原理同20
26.?public static int lastIndexOf(String str, String searchStr, int startPos)?
??? 基本原理同22
感謝以下博客:http://blog.csdn.net/qiaoning13256/article/details/6910570
? ? ? ? ? ? ? ? ?http://blog.csdn.net/lan410812571/article/details/9946991
? ? ? ? ? ? ? ? ?http://blog.csdn.net/jake9602/article/details/13768525
? ? ? ? ? ? ? ? ?http://www.tuicool.com/articles/FB7NryV
? ? ? ? ? ? ? ? ?http://blog.csdn.net/as425017946/article/details/49175635
?? ? ? ? ? ? ? ? http://blog.csdn.net/u014614038/article/details/47423757
? ? ? ? ? ? ? ? ?http://blog.csdn.net/qq_33113141/article/details/52162372
總結
以上是生活随笔為你收集整理的学习笔记之——Android常用属性归纳的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 你会用Push Mail吗?(转)
- 下一篇: android 开发 字体,Androi