string.xml中添加空格
假设TextView引用了string.xml中的常量,若要在字符串开头添加空格或制表符,或者在字符串中间显示多个空格符,直接键盘敲入空格是不会在控件中起作用,需要使用: "   ;" 或者 " \t "等特殊字符:
- < string name = "test1" > \t填写    手机号 </ string >
- < string name = "test2" > 输入密码(6-14位) </ string > <!--开头空格无效-->
- < string name = "test3" > 已阅读并同意xx协议 </ 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);
密码输入框内容的显示和隐藏
- if (isChecked){
- //显示密码框内容
- mEditPwd.setInputType(InputType.TYPE_CLASS_TEXT|EditorInfo.TYPE_TEXT_VARIATION_NORMAL);
- //mEditPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
- } else {
- //隐藏密码框内容
- mEditPwd.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
- //mEditPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
- }
- mEditPwd.setSelection(mEditPwd.getText().toString().length()); //设置光标位置在文本框末尾
备注:"InputType.TYPE_CLASS_TEXT "表示都要添加,否则光标不显示;
让Activity全屏
-
在AndroidManif.xml对应的Activity节点中配置theme属性,如下:
- android:theme = "@android:style/Theme.Light.NoTitleBar.Fullscreen"
-
在Activity的onCreate()方法中设置:
- @Override
- protected void onCreate(BundlesavedInstanceState){
- super .onCreate(savedInstanceState);
- //隐藏标题栏,必须写在setContentView()之前
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- //隐去状态栏(电池等图标)
- 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();
- }
获取网络状态
- 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表示无网络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;
- }
- }
另外,需要添加访问网络状态的权限:
- < uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" />
发送简单短信
- < uses-permission android:name = "android.permission.SEND_SMS" />
- //发送短信
- SmsManagersms=SmsManager.getDefault();
- //sms.sendTextMessage("收信人号码","发件人号码,null表示当前设备可用号码","发送内容",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 );
- }
介绍另一种发短信方法:
- 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中设置自定义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中设置Activity主题:
- <activity
- android:name= ".SecondActivity"
- android:theme= "@style/HalfTranslucent"
- android:label= "@string/title_activity_second" >
- </activity>
a. 反编译他人的apk文件会出现类似如下情况的语句,多了个星号,删掉即可- "@*android:style/Theme.Translucent"
- java.lang.IllegalStateException:YouneedtouseaTheme.AppCompattheme(ordescendant)with this activity.
引用http://blog.csdn.net/zxz_tsgx/article/details/38343333