十一
04
透明的activity:
AndroidManifest.xml中找到要弹出的activity,加入theme:
android:theme=”@style/translucent”
res/values文件夹下建立styles.xml:
再新建colors.xml:
前2位:透明度00完全透明,99不透明
后6位:颜色
*有时候需要重启一下emulator,才会显示出透明颜色
#60000000
代码:
translucent
代码:
testToast
自定义view:
新建一个包com.view:
package com.view;
import com.test.R;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class InputMode extends RelativeLayout {
public static String TAG = "InputMode";
public TextView label;
public EditText text;
public InputMode(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public InputMode(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public InputMode(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public void initView() {
Log.d(TAG, "initView()");
this.label = (TextView) findViewById(R.id.input_mode_label);
this.text = (EditText) findViewById(R.id.input_mode_text);
this.text.getText();
}
/**
* 设置label文本
* @param str
*/
public void setLabelText(String str) {
this.label.setText(str);
}
/**
* 设置输入框内容
* @param str
*/
public void setInputText(String str) {
this.text.setText(str);
}
/**
* 设置输入框显示为密码
* @param flag
*/
public void setInputTextMode(boolean flag) {
if(flag) {
this.text.setTransformationMethod(android.text.method.PasswordTransformationMethod.getInstance());
} else {
this.text.setTransformationMethod(null);
}
}
/**
* 获得输入框内容
* @return
*/
public String getInputText() {
return this.text.getText().toString();
}
/**
* 设置label宽度
* @param width
*/
public void setLabelWidth(Integer width) {
this.label.setWidth(width);
}
}
之后新建一个layout:
调用:
在要加入自定义view的layout中:
activity中:
InputMode username_im;
username_im = (InputMode) findViewById(R.id.username_input);
username_im.initView();
username_im.setLabelText("Username:");
username_im.setInputText("");
代码:
customView



no comment untill now