Android五種不同樣式Toast-創(chuàng)新互聯(lián)

廢話(huà)不多說(shuō),直接上代碼:

創(chuàng)新互聯(lián)建站"三網(wǎng)合一"的企業(yè)建站思路。企業(yè)可建設(shè)擁有電腦版、微信版、手機(jī)版的企業(yè)網(wǎng)站。實(shí)現(xiàn)跨屏營(yíng)銷(xiāo),產(chǎn)品發(fā)布一步更新,電腦網(wǎng)絡(luò)+移動(dòng)網(wǎng)絡(luò)一網(wǎng)打盡,滿(mǎn)足企業(yè)的營(yíng)銷(xiāo)需求!創(chuàng)新互聯(lián)建站具備承接各種類(lèi)型的成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作項(xiàng)目的能力。經(jīng)過(guò)十年的努力的開(kāi)拓,為不同行業(yè)的企事業(yè)單位提供了優(yōu)質(zhì)的服務(wù),并獲得了客戶(hù)的一致好評(píng)。

package com.otn.android.toast;

import android.app.Activity;

import android.app.AlertDialog;

import android.os.Bundle;

import android.view.Gravity;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.TextView;

import android.widget.Toast;

public class MyToast extends Activity implements OnClickListener {

private static final String TOASTBTN_1 = "這是默認(rèn)的Toast顯示";

private static final String TOASTBTN_2 = "這是自定義位置的Toast顯示";

private static final String TOASTBTN_3 = "這是帶圖片的Toast顯示";

private static final String TOASTBTN_4 = "這是完全自定義的Toast顯示";

private static final String TOASTBTN_5 = "這是長(zhǎng)時(shí)間的Toast顯示";

private Button toastBtn_1, toastBtn_2, toastBtn_3, toastBtn_4, toastBtn_5;

private Toast toast = null;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

toastBtn_1 = (Button) findViewById(R.id.button_1);

toastBtn_2 = (Button) findViewById(R.id.button_2);

toastBtn_3 = (Button) findViewById(R.id.button_3);

toastBtn_4 = (Button) findViewById(R.id.button_4);

toastBtn_5 = (Button) findViewById(R.id.button_5);

toastBtn_1.setOnClickListener(this);

toastBtn_2.setOnClickListener(this);

toastBtn_3.setOnClickListener(this);

toastBtn_4.setOnClickListener(this);

toastBtn_5.setOnClickListener(this);

}

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

AlertDialog.Builder builder;

AlertDialog dialog;

switch (v.getId()) {

case R.id.button_1:

toast.makeText(this, TOASTBTN_1, Toast.LENGTH_LONG).show();

break;

case R.id.button_2:

toast = Toast.makeText(getApplicationContext(), TOASTBTN_2,

Toast.LENGTH_LONG);

toast.setGravity(Gravity.CENTER, 0, 0);

toast.show();

break;

case R.id.button_3:

toast = Toast.makeText(getApplicationContext(), TOASTBTN_3,

Toast.LENGTH_LONG);

toast.setGravity(Gravity.CENTER, 50, -100);

LinearLayout layout = (LinearLayout) toast.getView();

ImageView p_w_picpath = new ImageView(getApplicationContext());

p_w_picpath.setImageResource(R.drawable.wallpaper_tree_small);

layout.addView(p_w_picpath, 0);

toast.show();

break;

case R.id.button_4:

LayoutInflater inflater = getLayoutInflater();

View view = inflater.inflate(R.layout.userdefinedtoast,

(ViewGroup) findViewById(R.id.toast_layout));

TextView txtView_Title = (TextView) view

.findViewById(R.id.txt_Title);

TextView txtView_Context = (TextView) view

.findViewById(R.id.txt_context);

ImageView p_w_picpathView = (ImageView) view

.findViewById(R.id.p_w_picpath_toast);

toast = new Toast(getApplicationContext());

toast.setGravity(Gravity.CENTER, 0, 0);

toast.setDuration(Toast.LENGTH_LONG);

toast.setView(view);

toast.show();

break;

case R.id.button_5:

LayoutInflater inflater1 = getLayoutInflater();

View view1 = inflater1.inflate(R.layout.userdefinedtoast,

(ViewGroup) findViewById(R.id.toast_layout));

TextView txtView_Title1 = (TextView) view1

.findViewById(R.id.txt_Title);

TextView txtView_Context1 = (TextView) view1

.findViewById(R.id.txt_context);

ImageView p_w_picpathView1 = (ImageView) view1

.findViewById(R.id.p_w_picpath_toast);

builder = new AlertDialog.Builder(this);

builder.setView(view1);

dialog = builder.create();

dialog.show();

break;

default:

break;

}

}

}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線(xiàn),公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。

文章題目:Android五種不同樣式Toast-創(chuàng)新互聯(lián)
瀏覽地址:http://bm7419.com/article14/djhige.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版網(wǎng)站收錄、網(wǎng)站營(yíng)銷(xiāo)、網(wǎng)站建設(shè)域名注冊(cè)、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)