最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)實現(xiàn)自定義Toast、LayoutInflater使用其他布局示例

 更新時間:2019年03月19日 11:44:19   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)實現(xiàn)自定義Toast、LayoutInflater使用其他布局,涉及Android自定義Toast與界面布局相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了Android開發(fā)實現(xiàn)自定義Toast、LayoutInflater使用其他布局。分享給大家供大家參考,具體如下:

內(nèi)容:

1.自定義樣式toast

2.再活動中添加其他布局

實現(xiàn)效果:

步驟:

一、自定義View 引用zidingyixml文件 生成一個布局對象

二、采用Toast 的addView() 方法將該對象添加到Toast對象中

三、顯示:Toast.show()

具體實現(xiàn)方法:

public class MainActivity extends Activity {
  Toast toast;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //應(yīng)用布局文件
    View insideView = LayoutInflater.from(MainActivity.this).inflate(R.layout.cell, null);
    LinearLayout linearLayout = (LinearLayout) insideView.findViewById(R.id.cell);
    ImageView imageView = (ImageView) insideView.findViewById(R.id.image1_Toast);
    TextView textView = (TextView) insideView.findViewById(R.id.textToast);
    imageView.setImageResource(R.drawable.warming);
    textView.setText("你的app 炸了!!");
    //建立提示消息對象
    toast = new Toast(this);
    toast.setView(insideView);
  }
  //按鈕點擊時彈出
  public void prev(View source){
    toast.show();
  }
}

注:R.layout.cell 中的cell 就是自定義的布局文件

建立步驟 在/values文件夾下 呢哇一個xml文件即可,內(nèi)容如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  android:id="@+id/cell"
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="horizontal">
  <ImageView
    android:id="@+id/image1_Toast"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
  <TextView
    android:id="@+id/textToast"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="15dp"/>
</LinearLayout>

最后給出整體的布局文件

<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:gravity="center_horizontal">
    <Button
      android:onClick="prev"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentLeft="true"/>
</RelativeLayout>

注:采用了 android:onClick="prev" 方法 在布局文件中直接添加了點擊事件,故MainActivity中不用手動添加onClickListener

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》及《Android資源操作技巧匯總

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

  • Android利用RecyclerView編寫聊天界面

    Android利用RecyclerView編寫聊天界面

    這篇文章主要為大家詳細(xì)介紹了Android利用RecyclerView編寫聊天界面,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Android自定義View之繪制圓形頭像功能

    Android自定義View之繪制圓形頭像功能

    這篇文章主要介紹了Android自定義View之繪制圓形頭像功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-09-09
  • Android 暫停和恢復(fù)Activity

    Android 暫停和恢復(fù)Activity

    在正常的應(yīng)用程序使用,前臺activity有時會被其他可視化組件遮擋,從而 造成activity的暫停。例如,當(dāng)一個半透明的activity打開時(如在一個風(fēng)格對話框),以前的activity就暫停了。只要 activity仍然是部分可見,但目前沒有獲得焦點,它就依然處于暫停狀態(tài)
    2016-03-03
  • android中g(shù)zip數(shù)據(jù)壓縮與網(wǎng)絡(luò)框架解壓縮

    android中g(shù)zip數(shù)據(jù)壓縮與網(wǎng)絡(luò)框架解壓縮

    這篇文章主要為大家介紹了android中g(shù)zip數(shù)據(jù)壓縮與網(wǎng)絡(luò)框架解壓縮實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • Android?Studio開發(fā)實現(xiàn)簡單計算器功能

    Android?Studio開發(fā)實現(xiàn)簡單計算器功能

    這篇文章主要為大家詳細(xì)介紹了Android?Studio開發(fā)實現(xiàn)簡單計算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • android Jsoup獲取網(wǎng)站內(nèi)容 android獲取新聞標(biāo)題實例

    android Jsoup獲取網(wǎng)站內(nèi)容 android獲取新聞標(biāo)題實例

    這篇文章主要為大家詳細(xì)介紹了android Jsoup獲取網(wǎng)站內(nèi)容,android獲取新聞標(biāo)題實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android 圖片特效如何實現(xiàn)及總結(jié)

    Android 圖片特效如何實現(xiàn)及總結(jié)

    這篇文章主要介紹了Android 圖形特效如何實現(xiàn)及總結(jié)的相關(guān)資料,這里對Android圖像特效的實現(xiàn)比如:旋轉(zhuǎn),放大,縮小,傾斜等,需要的朋友可以參考下
    2016-12-12
  • 最新評論

    缙云县| 句容市| 武安市| 荆门市| 横山县| 襄汾县| 闵行区| 贵溪市| 宁陕县| 临海市| 高淳县| 永寿县| 图们市| 仁怀市| 青田县| 石狮市| 上栗县| 离岛区| 蛟河市| 秦安县| 韶关市| 博白县| 澄迈县| 汽车| 来安县| 罗城| 临泉县| 乌审旗| 获嘉县| 永川市| 通山县| 贞丰县| 山阴县| 阳城县| 山阳县| 南木林县| 榆树市| 旬阳县| 西青区| 雷州市| 德钦县|