標籤:
1、TextView 內容過長時的省略和滾動
android:singleline="true", // 單行
android:ellipsize="" , // start middle end 省略的位置
android: marqueeRepeatLimit="" // marquee 跑馬燈 marquee_forever一直滾動
2、調用系統內建的工具傳輸檔案
intent.setAction(Intent.ACTION_SEND).setType("*/*").putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)).
調用藍芽傳輸:
setAction(Intent.ACTION_BLUETOOTH);
3、Intent
顯式Intent:通過指定Intent組件名稱來實現的,它一般用在知道目標組件名稱的前提下,一般是在相同的應用程式內部實現的。
隱式Intent:通過Intent Filter來實現的,它一般用在沒有明確指出目標組件名稱的前提下,一般是用於在不同應用程式之間。
setType和setData方法會清空彼此,android提供了一個setDataAndType()方法解決
view plaincopy to clipboardprint?
- public Intent setData(Uri data) {
- mData = data;
- mType = null;
- return this;
- }
view plain
- public Intent setType(String type) {
- mData = null;
- mType = type;
- return this;
- }
4、 ActionBar:
setDisplayHomeAsUpEnabled(boolean enable) 是否顯示返回表徵圖
public boolean onOptionsItemSelected(MenuItem item) {
case android.R.id.home:
setDisplayShowTitileEnabled() ...
5、 自訂Theme:
android:elevation ActionBar陰影的寬度 @null沒有
android:colorPrimaryDark 螢幕最上面狀態列
android:homeAsUpIndicator actionBar返回箭頭 @drawable/ic_arrow_back_24dp
android:actionOverFlowButtonStyle actionBar
<!-- Action bar overflow menu icon. -->
<style name="BlacklistActionBarOverflowQP" parent="@android:style/Widget.Material.Light.ActionButton.Overflow">
<item name="android:src">@drawable/ic_menu_overflow_lt</item>
</style>
6、 Androidxliff XML Localization Interchange File Format: xml本機資料交換格式
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="mms_size_expiry">"Message size: <xliff:g id="COUNT">%1$d</xliff:g> KB,   Expires: <xliff:g id="TIME">%2$s</xliff:g>"</string>
mContext.getString(R.string.mms_size_expiry, size, expiry)
%n$s n表示第幾個參數, s是字串
%n$ms m表示的總長度,如果字串長度大於m,則顯示字串,如果小於,則在字串後顯示相差個數的空格
%n$md m填0
%n$mf m=2.3 格式00.000
7、 擷取對簡訊操作的許可權:
Android5.0對於簡訊的插入和修改許可權進行控制,只有系統預設簡訊應用才能對簡訊進行操作。許可權管理類:
AppOpsManager.java AppOpsService.java// 擷取許可權:PackageManager packageManager = context.getPackageManager();AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);PackageInfo info = packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.GET_UNINSTALLED_PACKAGES);boolean isIgnored = AppOpsManager.MODE_IGNORED == appOpsManager.checkOp(AppOpsManager.OP_WRITE_SMS, info.applicationInfo.uid, PACKAGE_NAME);if (isIgnored) { // 開啟 appOpsManager.setMode(AppOpsManager.OP_WRITE_SMS, info.applicationInfo.uid, PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);}if (isIgnored) { // 關閉 appOpsManager.setMode(AppOpsManager.OP_WRITE_SMS, info.applicationInfo.uid, PACKAGE_NAME, AppOpsManager.MODE_IGNORED);}Permission; <uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />
8、 更改系統預設簡訊應用:
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, selfPackageName);startActivity(intent);Telephony.Sms.getDefaultSmsPackage(Context context) // 擷取預設簡訊應用的packageName
Android 小的知識片