欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)現(xiàn)微信右側(cè)頂部下拉對(duì)話框

 更新時(shí)間:2018年12月21日 17:04:25   作者:hfut_why  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)微信右側(cè)頂部下拉對(duì)話框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

我們使用微信都知道,其右側(cè)頂部有一個(gè)下拉對(duì)話框,我們可以執(zhí)行添加好友,掃一掃等功能,今天我們就來(lái)模仿實(shí)現(xiàn)一下這個(gè)功能(實(shí)現(xiàn)的方式有很多種,我今天只說(shuō)一種借助透明主題Activity的方式實(shí)現(xiàn);如果有興趣還可以移步至仿淘寶底部導(dǎo)航欄);本篇的實(shí)現(xiàn)的效果如下:

下面就來(lái)說(shuō)一說(shuō)實(shí)現(xiàn)的思路重要

第一步:創(chuàng)建彈出對(duì)話框布局

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >
 
 <RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_marginTop="45dp"
  android:layout_marginRight="20dp">
 
  <LinearLayout
   android:id="@+id/id_pop_dialog_layout"
   android:layout_width="@dimen/pop_list_width"
   android:layout_height="wrap_content"
   android:layout_alignParentRight="true"
   android:layout_alignParentTop="true"
   android:background="@drawable/pop_item_normal"
   android:orientation="vertical" >
 
   <LinearLayout
    android:id="@+id/upload_record_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:background="@drawable/pop_list_selector" >
 
    <ImageView
     android:id="@+id/id_imageView1"
     android:layout_width="@dimen/pop_dialog_icon_size"
     android:layout_height="@dimen/pop_dialog_icon_size"
     android:layout_gravity="center_vertical"
     android:layout_marginLeft="8dp"
     android:src="@drawable/upload_icon_record" />
 
    <TextView
     android:layout_width="@dimen/pop_list_width"
     android:layout_height="wrap_content"
     android:padding="8dp"
     android:text="@string/uploadRecord"
      android:layout_gravity="center_vertical"
     android:textColor="#fff"
     android:textSize="16sp" />
   </LinearLayout>
 
   <ImageView
    android:id="@+id/id_imageView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/pop_line" />
 
   <LinearLayout
    android:id="@+id/register_record_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:background="@drawable/pop_list_selector" >
 
    <ImageView
     android:id="@+id/id_imageView2"
     android:layout_width="@dimen/pop_dialog_icon_size"
     android:layout_height="@dimen/pop_dialog_icon_size"
     android:layout_gravity="center_vertical"
     android:layout_marginLeft="8dp"
     android:src="@drawable/register_icon_record" />
 
    <TextView
     android:layout_width="@dimen/pop_list_width"
     android:layout_height="wrap_content"
     android:padding="8dp"
     android:text="@string/registerRecord"
      android:layout_gravity="center_vertical"
     android:textColor="#fff"
     android:textSize="16sp" />
   </LinearLayout>
 
   <ImageView
    android:id="@+id/id_imageView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/pop_line" />
 
   <LinearLayout
    android:id="@+id/new_massage_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:background="@drawable/pop_list_selector" >
 
    <ImageView
     android:id="@+id/id_imageView3"
     android:layout_width="@dimen/pop_dialog_icon_size"
     android:layout_height="@dimen/pop_dialog_icon_size"
     android:layout_gravity="center_vertical"
     android:layout_marginLeft="8dp"
     android:src="@drawable/message_icon_tip" />
 
    <TextView
     android:id="@+id/new_message"
     android:layout_width="@dimen/pop_list_width"
     android:layout_height="wrap_content"
     android:padding="8dp"
     android:text="@string/defaultMessage"
     android:layout_gravity="center_vertical"
     android:textColor="#fff"
     android:textSize="16sp" />
   </LinearLayout>
 
   <ImageView
    android:id="@+id/id_imageView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/pop_line" />
 
  </LinearLayout>
 </RelativeLayout>
 
</RelativeLayout>

第二步:創(chuàng)建一個(gè)用于顯示該對(duì)話框布局Activity

package com.hfut.popdialogtest;
 
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.LinearLayout;
 
/**
 * @author why
 * @date 2018-10-3
 */
public class MyDialogActivity extends Activity implements OnClickListener{
 
 private LinearLayout uploadRecord;
 private LinearLayout registerRecord;
 private LinearLayout newMessage;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.pop_dialog);
 
  if(getActionBar()!=null){
   getActionBar().hide();
  }
  CommonTools.setNavbarVisibility(this);
  initView();
 }
 
 
 private void initView(){
  uploadRecord = findViewById(R.id.upload_record_layout);
  registerRecord = findViewById(R.id.register_record_layout);
  newMessage = findViewById(R.id.new_massage_layout);
 
  uploadRecord.setOnClickListener(this);
  registerRecord.setOnClickListener(this);
  newMessage.setOnClickListener(this);
 }
 
 @Override
 public boolean onTouchEvent(MotionEvent event){
  finish();
  return true;
 }
 
 @Override
 public void onClick(View v) {
  switch (v.getId()){
   case R.id.upload_record_layout:
   SharedData.resultID=1;
   break;
   case R.id.register_record_layout:
   SharedData.resultID=2;
   break;
   case R.id.new_massage_layout:
   SharedData.resultID=3;
   break;
   default:
   SharedData.resultID=0;
   break;
  }
  this.finish();
 }
}

第三步:創(chuàng)建一個(gè)主界面
MainActivity.java代碼:

package com.hfut.popdialogtest;
 
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
 
/**
 * @author why
 * @date 2018-10-3 9:35:35
 */
public class MainActivity extends AppCompatActivity {
 
 TextView resultShow;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  resultShow = findViewById(R.id.show_choosen_result);
 
  if(getActionBar()!=null){
   getActionBar().hide();
  }
  CommonTools.setNavbarVisibility(this);
 }
 
 
 @Override
 protected void onResume() {
  switch (SharedData.resultID) {
   case 0:
    resultShow.setText("默認(rèn)顯示");
    break;
   case 1:
    resultShow.setText(getResources().getString(R.string.uploadRecord));
    break;
   case 2:
    resultShow.setText(getResources().getString(R.string.registerRecord));
    break;
   case 3:
    resultShow.setText(getResources().getString(R.string.defaultMessage));
    break;
   default:
    resultShow.setText("默認(rèn)顯示");
    break;
 
  }
  super.onResume();
 }
 
 public void openPopDialog(View view) {
  Intent intent = new Intent(this, PopDialogActivity.class);
  startActivity(intent);
 }
}

activity_main.xml代碼:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.hfut.popdialogtest.MainActivity">
 
 <ImageView
  android:onClick="openPopDialog"
  android:id="@+id/pop_dialog_icon"
  app:layout_constraintRight_toRightOf="parent"
  android:layout_marginRight="10dp"
  app:layout_constraintTop_toTopOf="parent"
  android:layout_marginTop="5dp"
  android:background="@drawable/message_tip"
  android:layout_width="50dp"
  android:layout_height="50dp" />
 
 <TextView
  android:gravity="center"
  android:textColor="@color/colorAccent"
  android:textSize="30sp"
  android:id="@+id/show_choosen_result"
  app:layout_constraintTop_toBottomOf="@id/pop_dialog_icon"
  android:layout_marginTop="50dp"
  android:layout_width="match_parent"
  android:layout_height="match_parent" />
 
</android.support.constraint.ConstraintLayout>

第四步:設(shè)置對(duì)話框Activity主題為透明主題
AndroidManifest.xml文件代碼:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.hfut.popdialogtest">
 
 <application
  android:allowBackup="true"
  android:icon="@mipmap/ic_launcher"
  android:label="@string/app_name"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:supportsRtl="true"
  android:theme="@style/AppTheme">
  <activity android:name=".MainActivity">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
 
    <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>
  <activity android:name=".MyDialogActivity" android:theme="@android:style/Theme.Translucent" />
 </application>
 
</manifest>

第五步:其他輔助代碼
CommonTools.java代碼:

package com.hfut.popdialogtest;
 
import android.app.Activity;
import android.view.View;
 
/**
 * author:why
 * created on: 2018/9/11 13:34
 * description:
 */
public class CommonTools {
 
 /**
  * to controll the visibility of the Activity's navigator bar
  * @param activity
  */
 public static void setNavbarVisibility(Activity activity) {
  View decorView = activity.getWindow().getDecorView();
  decorView.setSystemUiVisibility(
    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
      | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
      | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
      | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
      | View.SYSTEM_UI_FLAG_FULLSCREEN
      | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
 }
 
}

Values目錄下的dimens.xml代碼:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <dimen name="pop_list_width">160dp</dimen>
 <dimen name="pop_dialog_icon_size">60dp</dimen>
 <dimen name="pop_dialog_icon_tip_size">40dp</dimen>
</resources>

Values目錄下的strings.xml代碼:

<resources>
 <string name="app_name">仿微信右側(cè)頂部下拉彈出測(cè)試</string>
 
 <string name="uploadRecord">上傳記錄</string>
 <string name="registerRecord">注冊(cè)記錄</string>
 <string name="defaultMessage">消息提示</string>
 
</resources>

其他資源文件就不添加了。我們總結(jié)一下其實(shí)就是這樣的步驟:

  • 點(diǎn)擊主Activity的彈窗對(duì)話框圖標(biāo),打開一個(gè)新的透明的Acitivity
  • 在新的Activity中做完邏輯處理把結(jié)果存放在主Activity可訪問的數(shù)據(jù)域,然后finish自己
  • 主Activity再次可交互,并在onResume中實(shí)現(xiàn)對(duì)處理結(jié)果分析和處理,比如修改主Activity UI; 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android 使用手機(jī)NFC的讀取NFC標(biāo)簽數(shù)據(jù)的方法

    Android 使用手機(jī)NFC的讀取NFC標(biāo)簽數(shù)據(jù)的方法

    這篇文章主要介紹了Android 使用手機(jī)NFC的讀取NFC標(biāo)簽數(shù)據(jù)的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧
    2018-07-07
  • Android簡(jiǎn)單的短信驗(yàn)證功能的實(shí)現(xiàn)代碼

    Android簡(jiǎn)單的短信驗(yàn)證功能的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android簡(jiǎn)單的短信驗(yàn)證功能的實(shí)現(xiàn)代碼,本文是小編使用sdk過程的一些心得,需要的朋友可以參考下
    2018-07-07
  • android I/0流操作文件(文件存儲(chǔ))

    android I/0流操作文件(文件存儲(chǔ))

    Java提供一套完整的I/О流體系,通過I/О流可以非常方便地訪問磁盤中的文件,同樣Android 也支持I/O流方式來(lái)訪問手機(jī)等移動(dòng)設(shè)備中的存儲(chǔ)文件。希望可以為大家提供幫助
    2021-06-06
  • Android微信簽名知識(shí)的總結(jié)

    Android微信簽名知識(shí)的總結(jié)

    這篇文章給大家詳細(xì)總結(jié)了Android微信簽名用到的知識(shí),文中通過具體的實(shí)現(xiàn)過程給大家進(jìn)行演示,相信對(duì)大家的理解很有幫助,下面來(lái)一起看看吧。
    2016-09-09
  • 淺談Android插件化

    淺談Android插件化

    插件化技術(shù)最初源于免安裝運(yùn)行 Apk的想法,這個(gè)免安裝的 Apk 就可以理解為插件,而支持插件的 app 我們一般叫 宿主,下面就跟著小編一起學(xué)習(xí)Android插件化吧,希望能幫助到你
    2021-09-09
  • 詳談Android ListView的選擇模式

    詳談Android ListView的選擇模式

    下面小編就為大家?guī)?lái)一篇詳談Android ListView的選擇模式。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧
    2017-04-04
  • Android編程實(shí)現(xiàn)鬧鐘的方法詳解

    Android編程實(shí)現(xiàn)鬧鐘的方法詳解

    這篇文章主要介紹了Android編程實(shí)現(xiàn)鬧鐘的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android鬧鐘的原理、布局、權(quán)限控制及相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2017-02-02
  • Android開發(fā)中DatePicker日期與時(shí)間控件實(shí)例代碼

    Android開發(fā)中DatePicker日期與時(shí)間控件實(shí)例代碼

    本文通過實(shí)例代碼給大家介紹了Android開發(fā)中DatePicker日期與時(shí)間控件,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-08-08
  • Android Flutter利用CustomPaint繪制基本圖形詳解

    Android Flutter利用CustomPaint繪制基本圖形詳解

    CustomPaint其實(shí)和前端的Canvas基本上是一樣的,前端Canvas支持的繪制方法CustomPaint都支持,畢竟CustomPaint其實(shí)也是基于Canvas實(shí)現(xiàn)的。本篇我們來(lái)介紹 CustomPaint 基本圖形的繪制,感興趣的可以了解一下
    2022-07-07
  • SimpleCommand框架ImageLoader API詳解(三)

    SimpleCommand框架ImageLoader API詳解(三)

    這篇文章主要為大家詳細(xì)介紹了SimpleCommand框架ImageLoader API,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10

最新評(píng)論