多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > 綜合技術(shù) > Android學(xué)習(xí)筆記之自定義Toast

Android學(xué)習(xí)筆記之自定義Toast

來源:程序員人生   發(fā)布時間:2015-01-23 08:51:51 閱讀次數(shù):3630次

(1)布局文件layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="104dp" android:layout_marginTop="70dp" android:text="普通的Toast" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/button1" android:layout_below="@+id/button1" android:layout_marginTop="50dp" android:text="自定義的Toast" /> </RelativeLayout>

(2)需要彈出的Toast布局文件

<?xml version="1.0" encoding="utf⑻"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toast_layout_root" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#DAA" android:orientation="horizontal" android:padding="8dp" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="8dp" android:src="@drawable/in" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="8dp" /> </LinearLayout>

(3)類的文件

package com.lc.toastdialog; import android.app.Activity; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private Button button1; private Button button2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button1 = (Button) this.findViewById(R.id.button1); button2 = (Button) this.findViewById(R.id.button2); /* * 普通的Toast */ button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "普通的Toast", Toast.LENGTH_SHORT).show(); } }); /* * 自定義的Toast */ button2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 找到toast這個layout View layout = LayoutInflater.from(MainActivity.this).inflate( R.layout.toast, null); // 對toast文件中的textView設(shè)置值 TextView textView = (TextView) layout.findViewById(R.id.text); textView.setText("hello world!"); Toast toast = new Toast(MainActivity.this); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout); toast.show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }



生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: www久久久 | 午夜伦理影院 | 亚洲人人爱 | 视频一区二区三区在线观看 | 亚洲综合久久综合激情久久 | 国产亚洲欧洲国产综合一区 | 国内精品久久久久影院亚洲 | 最近最全中文字幕 | 日韩一级欧美一级毛片在线 | 国产精品爱久久久久久久9999 | 亚洲已满18点击进入在线观看 | 欧美操老逼| 久久国内精品 | 亚洲天天综合 | 色综合91 | 亚洲国产精品久久久久久 | 成人资源在线观看 | yellow中文字幕视频在线 | 欧美亚洲国产精品第一页 | 手机在线精品视频每日更新 | 亚洲欧洲国产视频 | 亚洲综合网在线观看 | 性欧美video在线播放 | 亚洲成a v人片在线观看 | 蜜桃精品免费久久久久影院 | 日韩精品在线播放 | 狠狠躁 | 成人免费视频网 | 国产精品国产三级国产专区5o | 亚洲人成图片欧美人成图片 | 男人激烈吃奶好舒服 | 午夜啪啪网 | 99久久精品国产综合一区 | 日本中文字幕网址 | 国内自拍视频在线看免费观看 | 精品视频一区二区三区四区 | 亚洲精品高清在线 | 免费网站看v片在线观看 | a毛片全部播放免费视频完整18 | 在线观看免费 | 在线中文字幕第一页 |