亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Verzeichnis suchen
android Manifest Manifest.permission Manifest.permission_group android.accessibilityservice AccessibilityService android.accounts Account android.app NotificationManager android.bluetooth BluetoothAdapter BluetoothClass BluetoothClass.Device BluetoothClass.Device.Major BluetoothClass.Service BluetoothDevice BluetoothServerSocket BluetoothSocket android.content SharedPreferences android.database.sqlite SQLiteCursorDriver SQLiteOpenHelper android.graphics Bitmap android.location LocationListener Geocoder GpsStatus GpsStatus.Listener GpsStatus.NmeaListener GpsSatellite android.media AudioFormat AsyncPlayer AudioRecord AudioRecord.OnRecordPositionUpdateListener ThumbnailUtils AudioManager android.net TrafficStats MailTo LocalSocket android.os AsyncTask AsyncTask.Status CountDownTimer Message MessageQueue HandlerThread android.text Html android.util JsonWriter android.view ContextMenu ContextMenu.ContextMenuInfo Display ViewManager View ViewStub ViewTreeObserver ViewParent WindowManager GestureDetector Gravity MenuInflater ScaleGestureDetector SoundEffectConstants android.view.inputmethod InputConnection InputMethod InputMethodSession BaseInputConnection InputMethodManager android.widget AbsListView AbsListView.LayoutParams AbsListView.OnScrollListener AbsListView.RecyclerListener AbsoluteLayout AbsoluteLayout.LayoutParams AbsSeekBar AbsSpinner AdapterView AdapterView.AdapterContextMenuInfo AdapterView.OnItemLongClickListener AdapterView.OnItemSelectedListener AdapterView.OnItemClickListener AnalogClock BaseAdapter BaseExpandableListAdapter Button CheckBox CheckedTextView Checkable Chronometer Chronometer.OnChronometerTickListener CompoundButton CompoundButton.OnCheckedChangeListener CursorAdapter CursorTreeAdapter DatePicker DatePicker.OnDateChangedListener DialerFilter DigitalClock EditText Filter Filter.FilterListener Filter.FilterResults ExpandableListAdapter ExpandableListView.OnChildClickListener ExpandableListView.OnGroupClickListener ExpandableListView.OnGroupCollapseListener ExpandableListView.OnGroupExpandListener Filterable Gallery Gallery.LayoutParams GridView GridLayout GridLayout.Alignment RadioGroup ImageView ImageView.ScaleType HorizontalScrollView ImageButton ImageSwitcher FilterQueryProvider ListAdapter ListView MediaController MultiAutoCompleteTextView MultiAutoCompleteTextView.CommaTokenizer MultiAutoCompleteTextView.Tokenizer QuickContactBadge RadioButton RatingBar RatingBar.OnRatingBarChangeListener RelativeLayout RemoteViews ResourceCursorAdapter ResourceCursorTreeAdapter Scroller ScrollView SearchView SearchView.OnCloseListener SearchView.OnQueryTextListener SearchView.OnSuggestionListener SeekBar SeekBar.OnSeekBarChangeListener SimpleAdapter SimpleAdapter.ViewBinder SimpleCursorAdapter SimpleCursorAdapter.CursorToStringConverter SimpleCursorAdapter.ViewBinder SimpleCursorTreeAdapter SimpleCursorTreeAdapter.ViewBinder SimpleExpandableListAdapter SlidingDrawer SlidingDrawer.OnDrawerCloseListener SlidingDrawer.OnDrawerOpenListener SlidingDrawer.OnDrawerScrollListener Spinner SpinnerAdapter WrapperListAdapter TabHost TabHost.TabSpec TextView TimePicker TimePicker.OnTimeChangedListener Toast TableLayout TableLayout.LayoutParams TableRow TableRow.LayoutParams TabWidget TextSwitcher ToggleButton TwoLineListItem VideoView ViewAnimator ViewFlipper ViewSwitcher ViewSwitcher.ViewFactory ZoomButtonsController ZoomButtonsController.OnZoomListener ZoomButton ZoomControls dalvik.system DexFile
Figuren


Toast

翻譯時(shí)間:2010112

版本:Android 2.2 r1

?

類結(jié)構(gòu)

???????? public class Toast extends Object

?

java.lang.Object

android.widget.Toast

?

概述

????????

Toast是一種提供給用戶簡潔信息的視圖。Toast類幫助你創(chuàng)建和顯示該信息。

???????? 該視圖已浮于應(yīng)用程序之上的形式呈現(xiàn)給用戶。因?yàn)樗⒉猾@得焦點(diǎn),即使用戶正在輸入什么也不會(huì)受到影響。它的目標(biāo)是盡可能已不顯眼的方式,使用戶看到你提供的信息。有兩個(gè)例子就是音量控制和設(shè)置信息保存成功。

使用該類最簡單的方法就是調(diào)用一個(gè)靜態(tài)方法,讓他來構(gòu)造你需要的一切并返回一個(gè)新的 Toast 對(duì)象。

?

常量

???????? int ? LENGTH_LONG ?????

持續(xù)顯示視圖或文本提示較長時(shí)間。該時(shí)間長度可定制。

???????? 參見

?????????????????? setDuration(int)

?

int ? LENGTH_SHORT

持續(xù)顯示視圖或文本提示較短時(shí)間。該時(shí)間長度可定制。該值為默認(rèn)值。

???????? 參見

?????????????????? setDuration(int)

?

構(gòu)造函數(shù)

???????? public Toast (Context context)

???????? 構(gòu)造一個(gè)空的 Toast 對(duì)象。在調(diào)用 show() 之前,必須先調(diào)用 setView(View)。

(譯者注:只有使用setView(View)的時(shí)候,才使用new Toast(Content content)來得到Toast對(duì)象,否則必須用makeText()方法來創(chuàng)建toast對(duì)象,并且這種方式獲得Toast對(duì)象不能使用setText()方法。

???????? 參數(shù)

?????????????????? context??? 使用的上下文。通常是你的 Application Activity 對(duì)象。

?

公共方法

public int cancel ()

???????? 如果視圖已經(jīng)顯示則將其關(guān)閉,還沒有顯示則不再顯示。一般不需要調(diào)用該方法。正常情況下,視圖會(huì)在超過存續(xù)期間后消失。

?

public int getDuration ()

返回存續(xù)期間

?????? 請(qǐng)參閱

????????????? setDuration(int)

public int getGravity ()

???????? 取得提示信息在屏幕上顯示的位置。

?????????????????? 請(qǐng)參閱

??????????????????????????? Gravity

?????????? setGravity()

?

public float getHorizontalMargin ()

返回橫向欄外空白。

?

public float getVerticalMargin ()

返回縱向欄外空白。

?

public View getView ()

返回 View 對(duì)象。

請(qǐng)

setView(View)

?

public int getXOffset ()

返回相對(duì)于參照位置的橫向偏移像素量。

?????????????? Toast msg = Toast.makeText(Main.this, "Message", Toast.LENGTH_LONG);
?????????????? msg.setGravity(Gravity.CENTER, msg.getXOffset() / 2, msg.getYOffset() / 2);
?????????????? msg.show();

?

?

public int getYOffset ()

返回相對(duì)于參照位置的縱向偏移像素量。

?

public static Toast makeText (Context context, int resId, int duration)

生成一個(gè)從資源中取得的包含文本視圖的標(biāo)準(zhǔn) Toast 對(duì)象。

參數(shù)

??? context?? 使用的上下文。通常是你的 Application Activity 對(duì)象。

?????? resId?? ??要使用的字符串資源ID,可以是已格式化文本。

?????? duration? 該信息的存續(xù)期間。值為 LENGTH_SHORT LENGTH_LONG

異常

當(dāng)資源未找到時(shí)拋異常Resources.NotFoundException

?

public static Toast makeText (Context context, CharSequence text, int duration)

生成一個(gè)包含文本視圖的標(biāo)準(zhǔn) Toast 對(duì)象。

參數(shù)

context

使用的上下文。通常是你的 Application Activity 對(duì)象。

resId

要顯示的文本,可以是已格式化文本。

duration

該信息的存續(xù)期間。值為 LENGTH_SHORT LENGTH_LONG

?

?

public void setDuration (int duration)

設(shè)置存續(xù)期間。

請(qǐng)

LENGTH_SHORT

LENGTH_LONG

?

public void setGravity (int gravity, int xOffset, int yOffset)

設(shè)置提示信息在屏幕上的顯示位置。

(譯者注:自定義Toast的顯示位置,例如toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0)可以把Toast定位在左上角。Toast提示的位置xOffset:大于0向右移,小于0向左移

請(qǐng)

Gravity

getGravity()

?

public void setMargin (float horizontalMargin, float verticalMargin)

設(shè)置視圖的欄外空白。

參數(shù)

horizontalMargin???????? 容器的邊緣與提示信息的橫向空白(與容器寬度的比)。

verticalMargin???????????? 容器的邊緣與提示信息的縱向空白(與容器高度的比)。

?

public void setText (int resId)

更新之前通過 makeText() 方法生成的 Toast 對(duì)象的文本內(nèi)容。

參數(shù)

resId????? Toast 指定的新的字符串資源ID。

?

public void setText (CharSequence s)

更新之前通過 makeText() 方法生成的 Toast 對(duì)象的文本內(nèi)容。

參數(shù)

s?? Toast 指定的新的文本。

?

public void setView (View view)

設(shè)置要顯示的 View 。

(譯者注:注意這個(gè)方法可以顯示自定義的toast視圖,可以包含圖像,文字等等。是比較常用的方法。

請(qǐng)

getView()

?

public void show ()

按照指定的存續(xù)期間顯示提示信息。

?

補(bǔ)充

???????? 文章鏈接

?????????????????? Toast一直顯示的解決方法

?????????????????? 通知 Toast詳細(xì)用法(顯示view

?????????????????? Android一種信息提示機(jī)制:Toast

?????????????????? [推薦] android Toast大全(五種情形)建立屬于你自己的Toast

???????? 示例代碼

?????????????????? 示例一:使用圖片的Toast

??????????????????????????? Toast toast = new Toast(this);?

ImageView?view = new ImageView(this);?

view.setImageResource(R.drawable.icon);?

toast.setView(view);?

toast.show();

?

?????????????????? 示例二:帶文字帶圖片Toast

???????????????????????????

?????????????????? ???????? private void showToast() {

// 1 創(chuàng)建Toast

?????????????????? ?????????????????? Toast toast = Toast.makeText(this, "圖文顯示", Toast.LENGTH_LONG);

// 2 創(chuàng)建Layout,并設(shè)置為水平布局

?????????????????? ?????????????????? LinearLayout mLayout = new LinearLayout(this);

?????????????????? ?????????????????? mLayout.setOrientation(LinearLayout.HORIZONTAL);

?????????????????? ?????????????????? ImageView mImage = new ImageView(this); // 用于顯示圖像的ImageView

?????????????????? ?????????????????? mImage.setImageResource(R.drawable.icon);

?????????????????? ?????????????????? View toastView = toast.getView(); // 獲取顯示文字的Toast View

?????????????????? ?????????????????? mLayout.addView(mImage); // 添加到Layout

?????????????????? ?????????????????? mLayout.addView(toastView);

// 3 關(guān)鍵,設(shè)置Toast顯示的View(上面生成的Layout).

?????????????????? ?????????????????? toast.setView(mLayout);

?????????????????? ?????????????????? toast.show();

???????? ?????????????????? }

?

?????????????????? 示例三:綜合Toast例子

Main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

??? android:orientation="vertical"

??? android:layout_width="fill_parent"

??? android:layout_height="fill_parent"

??? >

<Button android:id="@+id/button1"

??? android:layout_width="fill_parent"

??? android:layout_height="wrap_content"

??? android:text="Toast顯示View"

/>

<Button android:id="@+id/button2"

??? android:layout_width="fill_parent"

??? android:layout_height="wrap_content"

??? android:text="Toast直接輸出"

/>

<Button android:id="@+id/button3"

??? android:layout_width="fill_parent"

??? android:layout_height="wrap_content"

??? android:text="VolumeToast應(yīng)用"

/>

</LinearLayout>

Toast.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

??? android:orientation="vertical"

??? android:layout_width="fill_parent"

??? android:layout_height="fill_parent"

??? >

<ImageView android:src="@drawable/toast"

??? android:layout_width="wrap_content"

??? android:layout_height="wrap_content"

/>

<TextView android:id="@+id/tv1"

??? android:text=""

??? android:layout_width="wrap_content"

??? android:layout_height="wrap_content"

/>

</LinearLayout>

Volumetoast.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

? android:layout_width="280dp"

? android:layout_height="wrap_content"

? android:gravity="center_horizontal"

? android:orientation="vertical"

? >

????????? <TextView??????????

????????????????? android:layout_width="fill_parent"

????????????????? android:layout_height="wrap_content"

????????????????? android:text="Volume"

????????? ?? />

????????? ?? <ProgressBar

????????????????? android:id="@+id/progress"

????????????????? android:layout_width="280dp"

????????????????? android:layout_height="wrap_content"

????????????????? android:progress="50"

????????????????? android:max="100"

????????????????? style="?android:attr/progressBarStyleHorizontal"

????????? ?? />

</LinearLayout>

Java代碼文件

public class toasttest extends Activity {

???

??????

??? @Override

??? public void onCreate(Bundle savedInstanceState) {

??????? super.onCreate(savedInstanceState);

??????? setContentView(R.layout.main);

??????? Button button1=(Button)findViewById(R.id.button1);

??????? button1.setOnClickListener(bt1lis);

??????? Button button2=(Button)findViewById(R.id.button2);

??????? button2.setOnClickListener(bt2lis);

??????? Button button3=(Button)findViewById(R.id.button3);

??????? button3.setOnClickListener(bt3lis);

? ??}

??? OnClickListener bt1lis=new OnClickListener(){

?

????????????? @Override

????????????? public void onClick(View v) {

???????????????????? showToast();

????????????? }

?

??? };

??? OnClickListener bt2lis=new OnClickListener(){

????????????? @Override

????????????? public void onClick(View v) {

???????????????????? Toast.makeText(toasttest.this,"直接輸出測試", Toast.LENGTH_LONG).show();

????????????? }

?

??? };

??? OnClickListener bt3lis=new OnClickListener(){

????????????? @Override

????????????? public void onClick(View v) {????????????

???????????????????? showvolumeToast();

????????????? }

?

??? };

??? public void showToast(){

? ???????? LayoutInflater li=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

??? ?????? View view=li.inflate(R.layout.toast,null);

??? ?????? //把布局文件toast.xml轉(zhuǎn)換成一個(gè)view

??? ?????? Toast toast=new Toast(this);

??? ?????? toast.setView(view);

??? ?????? //載入view,即顯示toast.xml的內(nèi)容

??? ?????? TextView tv=(TextView)view.findViewById(R.id.tv1);

??? ?????? tv.setText("Toast顯示View內(nèi)容");

??? ?????? //修改TextView里的內(nèi)容

??? ?????? toast.setDuration(Toast.LENGTH_SHORT);

??? ?????? //設(shè)置顯示時(shí)間,長時(shí)間Toast.LENGTH_LONG,短時(shí)間為Toast.LENGTH_SHORT,不可以自己編輯

??? ?????? toast.show();

??? }

?????? public void showvolumeToast() {

????????????? // TODO Auto-generated method stub

?????? ????? LayoutInflater li=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

??? ?????? View volumeView=li.inflate(R.layout.volumetoast,null);

??????? ((ProgressBar)volumeView.findViewById(R.id.progress)).setProgress(((ProgressBar)volumeView.findViewById(R.id.progress)).getProgress() + 10);

??????? //這里還有點(diǎn)問題,就是progress的進(jìn)度條不動(dòng),因?yàn)槲覀冎饕窍虢o大家展示

???? //Toast的用法,這里就不深究了

??????? Toast volumeToast= new Toast(this);

??????? volumeToast.setGravity(Gravity.BOTTOM, 0, 100);

??????? volumeToast.setView(volumeView);

??????? volumeToast.setDuration(Toast.LENGTH_SHORT);??????

??????? volumeToast.show();

?????? }

}

?

備注:我們的代碼沒有重復(fù)概述中的通過代碼布局toast實(shí)現(xiàn)方法,我們是通過布局文件轉(zhuǎn)換成view視圖來實(shí)現(xiàn)復(fù)雜toast,這是兩種常用的方法,大家可以根據(jù)具體情況進(jìn)行選擇。

下載

/Files/over140/2010/11/demo_Toast.rar

?

不足之處

????? 現(xiàn)象:當(dāng)點(diǎn)擊一個(gè)按鈕?可以顯示一個(gè)四秒的toast但是我要是連點(diǎn)兩下就是8 三下十二秒

????? 解決辦法:只用一個(gè)Toast, 自己設(shè)置toast.setText(), setDuration(); 之后無論多少次.show()都能馬上更新顯示, 一會(huì)就消失了


Vorheriger Artikel: N?chster Artikel: