日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > Android學習筆記之自定義Toast

Android學習筆記之自定義Toast

來源:程序員人生   發布時間:2015-01-23 08:51:51 閱讀次數:3633次

(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設置值 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; } }



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 久久久精 | 黄视频在线观看网站 | 成人影视免费 | 18视频网站在线观看 | 欧美日韩高清在线一区 | 日韩 国产 欧美 | 黄色欧美视频 | 91 久久 | 三级网站免费看 | 中文在线免费视频 | 亚洲精品在线电影 | 国产污视频在线 | 欧美不卡激情三级在线观看 | 性视频网 | 欧美日韩国产在线一区 | 九九人人 | 精品中文字幕一区 | 亚洲精品电影在线 | 草色在线 | 欧美成人激情视频 | 亚洲精品麻豆 | 国产一区二区三区久久 | 国产精品视频免费看 | 贼王1995| 不用播放器的av网站 | 日日操夜夜操狠狠操 | 亚洲国产99 | 综合久久一区 | 亚洲免费综合 | 最近中文字幕mv免费高清在线 | 日本中文字幕电影 | 91久久久久久久久久久久久 | 日韩特黄特色大片免费视频 | 女人黄色特级大片 | 在线黄色av | 欧日韩不卡在线视频 | 久久嫩草精品久久久精品 | 暖暖av| 日韩免费电影在线观看 | 久久99精品久久久久久久久久久久 | 狠狠热综合网 |