string.xml中添加空格
假設(shè)TextView引用了string.xml中的常量,若要在字符串開頭添加空格或制表符,或者在字符串中間顯示多個空格符,直接鍵盤敲入空格是不會在控件中起作用,需要使用: "   ;" 或者 " \t "等特殊字符:
- < string name = "test1" > \t填寫    手機號 </ string >
- < string name = "test2" > 輸入密碼(6-14位) </ string > <!--開頭空格無效-->
- < string name = "test3" > 已閱讀并同意xx協(xié)議 </ string > <!--中間部分只顯示一個空格-->
eclipse會提示test2中的"6-14"最好做修改 : Replace "-" with an "en dash" character (–, &&;#8211;) ?
處理方法是將" - "替換為 "– "即可;
P.S.: 帶html用法 ;
帶邊框的TextView
- <? xml version = "1.0" encoding = "utf-8" ?>
- < shape xmlns:android = "http://schemas.android.com/apk/res/android"
- android:shape = "rectangle" >
- < solid android:color = "@android:color/white" />
- < corners android:radius = "5dip" />
- < stroke android:width = "1dip" android:color = "#CBCBCB" />
- </ shape >
- android:background = "@drawable/regist_login_textview_border"
TextView添加刪除線
- mTextView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
密碼輸入框內(nèi)容的顯示和隱藏
- if (isChecked){
- //顯示密碼框內(nèi)容
- mEditPwd.setInputType(InputType.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_NORMAL);
- //mEditPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
- } else {
- //隱藏密碼框內(nèi)容
- mEditPwd.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
- //mEditPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
- }
- mEditPwd.setSelection(mEditPwd.getText().toString().length()); //設(shè)置光標位置在文本框末尾
備注:"InputType.TYPE_CLASS_TEXT "表示都要添加,否則光標不顯示;
讓Activity全屏
-
在AndroidManif.xml對應的Activity節(jié)點中配置theme屬性,如下:
- android:theme = "@android:style/Theme.Light.NoTitleBar.Fullscreen"
-
在Activity的onCreate()方法中設(shè)置:
- @Override
- protected void onCreate(BundlesavedInstanceState){
- super .onCreate(savedInstanceState);
- //隱藏標題欄,必須寫在setContentView()之前
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- //隱去狀態(tài)欄(電池等圖標)
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.activity_main);
- }
禁止橫豎屏切換
- android:screenOrientation = "portrait"
引申:android:configChanges=”keyboardHidden|orientation” onConfigurationChanged(Configuration newConfig)
獲得程序版本號
- try {
- PackageManagerpkgMgr=getPackageManager();
- PackageInfoinfo=pkgMgr.getPackageInfo( this .getPackageName(), 0 );
- StringversionName=info.versionName;
- } catch (NameNotFoundExceptione){
- e.printStackTrace();
- }
獲取網(wǎng)絡(luò)狀態(tài)
- import android.content.Context;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- public final class ConnectivityUtils{
- private static ConnectivityManagerconnMgr= null ;
- private static NetworkInfoinfo= null ;
- private static int type=- 1 ; //-1表示無網(wǎng)絡(luò)ConnectivityManager.TYPE_NONE
- public static boolean isConnectivityAvailable(Contextcontext){
- connMgr=(ConnectivityManager)context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- info=connMgr.getActiveNetworkInfo();
- if (info== null ){
- return false ;
- }
- type=info.getType();
- return info.isAvailable();
- }
- public static boolean isWifiAvailable(Contextcontext){
- if (!isConnectivityAvailable(context)){
- return false ;
- }
- return type==ConnectivityManager.TYPE_WIFI;
- }
- public static boolean isMobileAvailable(Contextcontext){
- if (!isConnectivityAvailable(context)){
- return false ;
- }
- return type==ConnectivityManager.TYPE_MOBILE;
- }
- }
另外,需要添加訪問網(wǎng)絡(luò)狀態(tài)的權(quán)限:
- < uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" />
發(fā)送簡單短信
- < uses-permission android:name = "android.permission.SEND_SMS" />
- //發(fā)送短信
- SmsManagersms=SmsManager.getDefault();
- //sms.sendTextMessage("收信人號碼","發(fā)件人號碼,null表示當前設(shè)備可用號碼","發(fā)送內(nèi)容",null,null);
- sms.sendTextMessage(destinationAddress, null ,message, null , null );
- if (message.length()> 70 ){
- List<String>texts=sms.divideMessage(message);
- for (Stringtext:texts){
- sms.sendTextMessage(destinationAddress, null ,text, null , null );
- }
- } else {
- sms.sendTextMessage(destinationAddress, null ,message, null , null );
- }
介紹另一種發(fā)短信方法:
- public void sendSMS(Contextcontext,Stringcontent){
- Uriuri=Uri.parse( "smsto:153920*****" );
- Intentintent= new Intent(Intent.ACTION_SENDTO,uri);
- intent.putExtra(intent.EXTRA_TEXT,content);
- context.startActivity(intent);
- }
分享簡單文本信息
- public void shareText(Contextcontext,Stringcontent){
- Intentintent= new Intent(Intent.ACTION_SEND);
- intent.setType( "text/plain" );
- intent.putExtra(Intent.EXTRA_TEXT,content);
- context.startActivity(Intent.createChooser(intent,content));
- }
Activity毛玻璃半透明效果
-
在styles.xml中設(shè)置自定義style:
- <stylename= "HalfTranslucent" parent= "@android:style/Theme.Translucent" >
- <itemname= "android:windowBackground" > @color /half_tra</item>
- <itemname= "android:windowNoTitle" > true </item>
- <itemname= "android:windowAnimationStyle" > @android :style/Animation.Translucent</item>
- </style>
-
在string.xml或color.xml中添加色彩:
- <colorname= "half_tra" ># 90000000 </color>
-
在manifest.xml中設(shè)置Activity主題:
- <activity
- android:name= ".SecondActivity"
- android:theme= "@style/HalfTranslucent"
- android:label= "@string/title_activity_second" >
- </activity>
a. 反編譯他人的apk文件會出現(xiàn)類似如下情況的語句,多了個星號,刪掉即可- "@*android:style/Theme.Translucent"
- java.lang.IllegalStateException:YouneedtouseaTheme.AppCompattheme(ordescendant)with this activity.
引用http://blog.csdn.net/zxz_tsgx/article/details/38343333
更多文章、技術(shù)交流、商務合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
