内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

(三)android中Toast的使用-創(chuàng)新互聯(lián)

 一、Toasts(三)android中Toast
的使用

   A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message and the current activity remains visible and interactive. For example, navigating away from an email before you send it triggers a "Draft saved" toast to let you know that you can continue editing later. Toasts automatically disappear after a timeout.

創(chuàng)新互聯(lián)公司專注于羅莊網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供羅莊營(yíng)銷型網(wǎng)站建設(shè),羅莊網(wǎng)站制作、羅莊網(wǎng)頁設(shè)計(jì)、羅莊網(wǎng)站官網(wǎng)定制、小程序設(shè)計(jì)服務(wù),打造羅莊網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供羅莊網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。

二、The Basics

  First, instantiate a Toast object with one of the makeText() methods. This method takes three parameters: the application Context, the text message, and the duration for the toast. It returns a properly initialized Toast object. You can display the toast notification with show(), as shown in the following example:

Context context = getApplicationContext();
CharSequence text= "Hello toast!";
int duration = Toast.LENGTH_SHORT;

Toast toast= Toast.makeText(context, text, duration);
toast.show();

  This example demonstrates everything you need for most toast notifications. You should rarely need anything else. You may, however, want to position the toast differently or even use your own layout instead of a simple text message. The following sections describe how you can do these things.

  You can also chain your methods and avoid holding on to the Toast object, like this:

Toast.makeText(context, text, duration).show();

三、Positioning your Toast

  A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method. This accepts three parameters: aGravity constant, an x-position offset, and a y-position offset.

For example, if you decide that the toast should appear in the top-left corner, you can set the gravity like this:

toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);

  f you want to nudge the position to the right, increase the value of the second parameter. To nudge it down, increase the value of the last parameter.

四、Creating a Custom Toast View

  If a simple text message isn't enough, you can create a customized layout for your toast notification. To create a custom layout, define a View layout, in XML or in your application code, and pass the root View object to the setView(View) method.

For example, you can create the layout for the toast visible in the screenshot to the right with the following XML (saved as toast_layout.xml):

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/toast_layout_root"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="8dp"
              android:background="#DAAA"   >  <ImageViewandroid:src="@drawable/droid"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginRight="8dp" />  <TextViewandroid:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textColor="#FFF"   /></LinearLayout>

Notice that the ID of the LinearLayout element is "toast_layout_root". You must use this ID to inflate the layout from the XML, as shown here:

LayoutInflater inflater = getLayoutInflater();
View layout= inflater.inflate(R.layout.custom_toast,
                               (ViewGroup) findViewById(R.id.toast_layout_root));

TextView text= (TextView) layout.findViewById(R.id.text);
text.setText("This is a custom toast");

Toast toast= new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL,0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();

  First, retrieve the LayoutInflater with getLayoutInflater() (or getSystemService()), and then inflate the layout from XML using inflate(int, ViewGroup). The first parameter is the layout resource ID and the second is the root View. You can use this inflated layout to find more View objects in the layout, so now capture and define the content for the ImageView and TextView elements. Finally, create a new Toast with Toast(Context) and set some properties of the toast, such as the gravity and duration. Then call setView(View) and pass it the inflated layout. You can now display the toast with your custom layout by calling show().

   Note: Do not use the public constructor for a Toast unless you are going to define the layout withsetView(View). If you do not have a custom layout to use, you must use makeText(Context, int, int) to create the Toast.

分享標(biāo)題:(三)android中Toast的使用-創(chuàng)新互聯(lián)
當(dāng)前地址:http://www.rwnh.cn/article36/dsddpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、動(dòng)態(tài)網(wǎng)站、商城網(wǎng)站、網(wǎng)站制作、企業(yè)網(wǎng)站制作、網(wǎng)站建設(shè)

廣告

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

成都做網(wǎng)站
岳阳市| 越西县| 宁城县| 潮安县| 怀化市| 格尔木市| 崇礼县| 高台县| 河西区| 东城区| 沂南县| 大悟县| 涞源县| 栾城县| 高邮市| 张家口市| 开阳县| 商南县| 腾冲县| 长子县| 石林| 阳城县| 宝清县| 余干县| 新郑市| 大连市| 平果县| 舒城县| 贵定县| 平武县| 保德县| 安化县| 本溪| 南汇区| 宿州市| 恩施市| 吉木萨尔县| 塔河县| 浏阳市| 三门峡市| 沙田区|