Android 基礎一 TextView,Style樣式,Activity 傳值,選擇CheckBox 顯示密碼

來源:互聯網
上載者:User

標籤:

1.修改TextView字型

mTextView = (TextView) findViewById(R.id.textview1);mTextView.setText("I am here");Resources resources = getBaseContext().getResources();        Drawable myDrawable = resources.getDrawable(R.drawable.Drawable1);mTextView.setBackgroundDrawable(myDrawable);
mTextView.setTextSize(20);
mTextView.setTextColor(Color.WHITE);

  

2.擷取Android手機 螢幕解析度

DisplayMetrics dm = new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(dm);String spt = "手機解析度為"+dm.widthPixels+"x"+dm.heightPixels;

 

3.定義Style樣式

<TextView        style="@style/myStyle_tv1"        android:id="@+id/startapp_tv"        android:layout_width="fill_parent"        android:layout_height="match_parent"              android:background="#00BB00"        android:gravity="center"        android:text="@string/startapp_tv1 />    

然後在res/values/style.xml下加入

<resources><style name="myStyle_tv1"><item name="android:textSize">18sp</item><item name="android:textColor">#ffffff</item><style></resources>

  

4.不同Activity之間傳遞資料

(1)activity01中Intent intent = new Intent();intent.setClass(activity.this, activity2.class);Bundle bundle = new Bundle();bundle.putString("str_var1", "Hello");bundle.putDouble("dob_var1", 2.333);intent.putExtras(bundle);startActivity(intent);(2)activity02中Bundle bundle = this.getIntent().getExtras();string str = bundle.getString("str_var1");double db = bundle.getDouble("dob_var1");

5.startActivityForResult

(1)activity01中Intent intent = new Intent();intent.setClass(activity.this, activity2.class);Bundle bundle = new Bundle();bundle.putString("str_var1", "Hello");bundle.putDouble("dob_var1", 2.333);intent.putExtras(bundle);startActivityForResult(intent, 1);protected void onActivityResult(int requestCode, int resultCode, Intent data) {// TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);switch(requestCode){case 1://取得activity02的返回的資料                Bundle bundle2 = data.getExtras();                String str = bundle2.getString("str_var2");                double db = bundle2.getDouble("dob_var2");break;default:break;}}(2)activity02中Bundle bundle = this.getIntent().getExtras();string str = bundle.getString("str_var1");double db = bundle.getDouble("dob_var1");string str2 = "activity02 data";double db2 = 3.3333;

Button btn = (Button)findViewById(R.id.btn1);
btn.setOnClickListener(new Listener());

//定義一個監聽按鈕的類,這樣以後可以處理多個按鈕事件
class Listener implements OnClickListener{
public void onClick(View v){
    switch(v.getId()){
      case R.id.btn1:
        Intent intent = new Intent();
        intent.setClass(this, activity02.class);
        Bundle bd = new Bundle();
        bd.putString("str_var2", str2);
        bd.putDouble("dob_var2", db2);
        intent.putExtras(bd);
        activity02.this.setResult(1, intent);
        this.finish();
      break;
    }
  }
}

6.選擇CheckBox 顯示密碼

在OnCreate方法中

edit = (EditText)findViewById(R.id.pwd_edit);checkbox = (CheckBox)findViewById(R.id.pwd_checkbox);checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {  @Override  public void onCheckedChanged(CompoundButton arg0, boolean arg1) {    // TODO Auto-generated method stub      if(checkbox.isChecked()){      edit.setTransformationMethod(HideReturnsTransformationMethod.getInstance());;      }      else{
  edit.setTransformationMethod(PasswordTransformationMethod.getInstance());;   } }
})

  

Android 基礎一 TextView,Style樣式,Activity 傳值,選擇CheckBox 顯示密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.