假设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用法;
<?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>设置TextView控件的背景:
android:background="@drawable/regist_login_textview_border"效果如下:
mTextView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
@Override public boolean isFocused() { // 保证marquee效果可以实现,需要始终获取焦点 return true; }
android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"
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());//设置光标位置在文本框末尾
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //隐藏标题栏,必须写在setContentView()之前 requestWindowFeature(Window.FEATURE_NO_TITLE); //隐去状态栏(电池等图标) getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); }若只是通过代码来隐藏标题栏,则可以看到标题栏的消失动画(官方模拟器4.3测试),连同状态栏一起隐藏的话则无此问题;
android:screenOrientation="portrait"landscape -- 横向,portrait -- 纵向
try { PackageManager pkgMgr = getPackageManager(); PackageInfo info = pkgMgr.getPackageInfo(this.getPackageName(), 0); String versionName = info.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); }
import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public final class ConnectivityUtils { private static ConnectivityManager connMgr = null; private static NetworkInfo info = null; private static int type = -1; // -1 表示无网络 ConnectivityManager.TYPE_NONE public static boolean isConnectivityAvailable(Context context) { 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(Context context) { if (!isConnectivityAvailable(context)) { return false; } return type == ConnectivityManager.TYPE_WIFI; } public static boolean isMobileAvailable(Context context) { if (!isConnectivityAvailable(context)) { return false; } return type == ConnectivityManager.TYPE_MOBILE; } }通常在app中可能多出调用,这里直接做成了工具类,所以使用了final/static;
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SEND_SMS" />
// 发送短信 SmsManager sms = 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 (String text : texts) { sms.sendTextMessage(destinationAddress, null, text, null, null); } } else { sms.sendTextMessage(destinationAddress, null, message, null, null); }备注:这种方式是后台发送;
public void sendSMS(Context context, String content) { Uri uri = Uri.parse("smsto:153920*****"); Intent intent = new Intent(Intent.ACTION_SENDTO,uri); intent.putExtra(intent.EXTRA_TEXT, content); context.startActivity(intent); }不过这种方式需要手动单击发送;
public void shareText(Context context, String content) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, content); context.startActivity(Intent.createChooser(intent, content)); }系统会创建一个选择器,列出符合intent要求的app,从中选择再发送即可达到分享的目的,该方法也可以用来发送短信,只不过收件人需要手动填写;
<style name="HalfTranslucent" parent="@android:style/Theme.Translucent"> <item name="android:windowBackground">@color/half_tra</item> <item name="android:windowNoTitle">true</item> <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> </style>
<color name="half_tra">#90000000</color>
<activity android:name=".SecondActivity" android:theme="@style/HalfTranslucent" android:label="@string/title_activity_second" > </activity>我测试的效果貌似没网上那么好看,另外,测试过程中还碰到的问题:
"@*android:style/Theme.Translucent"b.运行时报错:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.我的adt插件版本23,新建工程时会有appcompat_v7库存在,在创建activity时默认继承的是actionbarActivity,改成Activity类即可;