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

Android實現(xiàn)短信、微信、微博分享功能

 更新時間:2017年12月25日 09:51:30   投稿:mrr  
微信、微博分享功能大家都體驗過吧,非常方便我們的生活,下面通過本文給大家介紹Android實現(xiàn)短信、微信、微博分享功能,需要的朋友參考下吧

在糾結(jié)了幾天的圖表功能之后,我開始開發(fā)一個新的功能。即分享內(nèi)容到短信、微信、微博等渠道,對應(yīng)的我有一個簡單的 Task:

  • 在 Toolbar 寫分享的按鈕
  • 繪制一個 Android 的分享頁面
  • 編寫短信分享示例
  • 編寫社交分享

在這一天,我只完成了前面的三部分。

Toolbar 上的分享按鈕

在 Toolbar 主要還是靠 ImageView 來繪制右上角的分享按鈕:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:toolbar="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/toolbar"
 android:layout_width="match_parent"
 android:layout_height="?attr/actionBarSize"
 android:background="?attr/colorPrimaryDark"
 android:gravity="center">
 <TextView
  android:id="@+id/toolbar_title"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  android:text="xxx" />
 <ImageView
  android:visibility="invisible"
  android:id="@+id/share"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:paddingEnd="@dimen/length_24"
  android:paddingStart="@dimen/length_16"
  android:paddingTop="@dimen/length_16"
  android:paddingBottom="@dimen/length_16"
  android:layout_gravity="right"
  android:src="@drawable/share_icon"
  tools:ignore="RtlHardcoded" />
</android.support.v7.widget.Toolbar>

然后在加載到數(shù)據(jù)的時候,將這個元素變?yōu)榭梢姡?/p>

share.setVisibility(View.VISIBLE);

短信分享示例

在實現(xiàn) UI 之前,我先寫了一個簡單的分享功能:

@OnClick(R.id.share)
void shareAction() {
 BaseShare smsShare = ShareFactory.create("SMS");
 String text = information.getTitle() + ":" + information.getTitle();
 smsShare.share(this, text);
}

隨后將其重構(gòu)為簡單的工廠模式:

public static BaseShare getShareType(String type) {
 switch (type) {
  case "SMS":
   return new SMSShare();
  case "WEIBO":
   return new WeiboShare();
  case "MOMENTS":
   return new MomentsShare();
  case "WECHAT":
   return new WechatShare();
 }
 return null;
}

對應(yīng)于不同的分享類型,都有不同的類來做相應(yīng)的處理。

使用 Dialog 繪制底部分享

在最開始的時候,我使用的是 Dialog 來繪制底部的布局:

void showShareDialog() {
 Dialog bottomDialog = new Dialog(this, R.style.BottomDialog);
 View contentView = LayoutInflater.from(this).inflate(R.layout.bottom_share, null);
 bottomDialog.setContentView(contentView);
 ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams();
 layoutParams.width = getResources().getDisplayMetrics().widthPixels;
 contentView.setLayoutParams(layoutParams);
 bottomDialog.getWindow().setGravity(Gravity.BOTTOM);
 bottomDialog.setCanceledOnTouchOutside(true);
 bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
 bottomDialog.show();
 }

然后簡單地了解了一下動畫效果:

<style name="BottomDialog">
 <item name="android:windowNoTitle">true</item>
 <item name="android:windowBackground">@android:color/transparent</item>
</style>
<style name="BottomDialog.Animation" parent="Animation.AppCompat.Dialog">
 <item name="android:windowEnterAnimation">@anim/translate_dialog_in</item>
 <item name="android:windowExitAnimation">@anim/translate_dialog_out</item>
</style>

對應(yīng)的動畫文件:

translate_dialog_in:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
 android:duration="300"
 android:fromXDelta="0"
 android:fromYDelta="100%"
 android:toXDelta="0"
 android:toYDelta="0">
</translate>

translate_dialog_out:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
 android:duration="300"
 android:fromXDelta="0"
 android:fromYDelta="0"
 android:toXDelta="0"
 android:toYDelta="100%">
</translate>

但是繪制的時候,出現(xiàn)了一些問題,即 Dialog 在最上面,隨后改用 BottomSheetDialog 來繪制。

使用 BottomSheetDialog 繪制分享菜單

對應(yīng)的邏輯變得更加簡單了。

void showShareDialog() {
 final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(DetailActivity.this);
 View dialogView = LayoutInflater.from(InformationDetailActivity.this).inflate(R.layout.bottom_share, null);
 dialogView.findViewById(R.id.cancel_share).setOnClickListener(view -> {
  bottomSheetDialog.dismiss();
 });
 bottomSheetDialog.setContentView(dialogView);
 bottomSheetDialog.show();
}

總結(jié)

以上所述是小編給大家介紹的Android實現(xiàn)短信、微信、微博分享功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Flutter實現(xiàn)自定義下拉選擇框的示例詳解

    Flutter實現(xiàn)自定義下拉選擇框的示例詳解

    在一些列表頁面中,我們經(jīng)常會有上方篩選項的的需求,點擊出現(xiàn)一個下拉菜單,而在Flutter中,并沒有現(xiàn)成的這樣的組件,所以最好我們可以自己做一個。本文將利用Flutter實現(xiàn)自定義下拉選擇框,需要的可以參考一下
    2022-04-04
  • android之SeekBar控件用法詳解

    android之SeekBar控件用法詳解

    下面小編就為大家?guī)硪黄猘ndroid之SeekBar控件用法詳解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-09-09
  • 使用Android Studio Gradle實現(xiàn)友盟多渠道打包

    使用Android Studio Gradle實現(xiàn)友盟多渠道打包

    這篇文章主要介紹了使用Android Studio Gradle實現(xiàn)友盟多渠道打包,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • OpenGL ES渲染管線概述(一)

    OpenGL ES渲染管線概述(一)

    這篇文章主要為大家詳細介紹了OpenGL ES渲染管線的簡單概述,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android 分享控件的實現(xiàn)代碼

    Android 分享控件的實現(xiàn)代碼

    這篇文章主要介紹了Android 分享控件的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • Android自定義DataGridView數(shù)據(jù)表格控件

    Android自定義DataGridView數(shù)據(jù)表格控件

    這篇文章主要介紹了Android自定義DataGridView數(shù)據(jù)表格控件的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android編程之軟鍵盤的隱藏顯示實例詳解

    Android編程之軟鍵盤的隱藏顯示實例詳解

    這篇文章主要介紹了Android編程之軟鍵盤的隱藏顯示,結(jié)合實例形式詳細分析了Android編程中軟鍵盤的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-12-12
  • Android仿微信長按菜單效果

    Android仿微信長按菜單效果

    這篇文章主要為大家詳細介紹了Android仿微信長按菜單效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • 詳解Android 視頻播放時停止后臺運行的方法

    詳解Android 視頻播放時停止后臺運行的方法

    這篇文章主要介紹了詳解Android 視頻播放時停止后臺運行的方法的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • Android實現(xiàn)左右滑動效果的方法詳解

    Android實現(xiàn)左右滑動效果的方法詳解

    本篇文章是對Android實現(xiàn)左右滑動效果的方法進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06

最新評論

高唐县| 贵南县| 天气| 漳平市| 驻马店市| 罗平县| 华阴市| 银川市| 奎屯市| 长子县| 八宿县| 仙桃市| 汉中市| 饶平县| 渭源县| 托克逊县| 华阴市| 饶平县| 盘山县| 临夏县| 沅陵县| 江川县| 无锡市| 龙州县| 察雅县| 临潭县| 扎囊县| 深水埗区| 新绛县| 武宁县| 香格里拉县| 嘉祥县| 平凉市| 宣化县| 屏东市| 剑阁县| 石嘴山市| 华宁县| 亳州市| 大兴区| 贺州市|