Android仿微信语音聊天功能

本文实例讲述了Android仿微信语音聊天功能代码。分享给大家供大家参考。具体如下:
项目效果如下:

具体代码如下:

AudioManager.java

package com.xuliugen.weichat;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import android.media.MediaRecorder;

public class AudioManager {
 private MediaRecorder mMediaRecorder;
 private String mDir;
 private String mCurrentFilePath;

 private static AudioManager mInstance;

 private boolean isPrepare;

 private AudioManager(String dir) {
 mDir = dir;
 }

 public static AudioManager getInstance(String dir) {
 if (mInstance == null) {
 synchronized (AudioManager.class) {
 if (mInstance == null) {
  mInstance = new AudioManager(dir);
 }
 }
 }
 return mInstance;
 }

 /**
 * 使用接口 用于回调
 */
 public interface AudioStateListener {
 void wellPrepared();
 }

 public AudioStateListener mAudioStateListener;

 /**
 * 回调方法
 */
 public void setOnAudioStateListener(AudioStateListener listener) {
 mAudioStateListener = listener;
 }

 // 去准备
 public void prepareAudio() {
 try {
 isPrepare = false;
 File dir = new File(mDir);
 if (!dir.exists()) {
 dir.mkdirs();
 }
 String fileName = generateFileName();
 File file = new File(dir, fileName);

 mCurrentFilePath =file.getAbsolutePath();

 mMediaRecorder = new MediaRecorder();
 // 设置输出文件
 mMediaRecorder.setOutputFile(dir.getAbsolutePath());
 // 设置MediaRecorder的音频源为麦克风
 mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 // 设置音频格式
 mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
 // 设置音频编码
 mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

 // 准备录音
 mMediaRecorder.prepare();
 // 开始
 mMediaRecorder.start();
 // 准备结束
 isPrepare = true;
 if (mAudioStateListener != null) {
 mAudioStateListener.wellPrepared();
 }

 } catch (IllegalStateException e) {
 e.printStackTrace();
 } catch (IOException e) {
 e.printStackTrace();
 }

 }

 /**
 * 随机生成文件的名称
 */
 private String generateFileName() {
 return UUID.randomUUID().toString() + ".amr";
 }

 public int getVoiceLevel(int maxlevel) {
 if (isPrepare) {
 try {
 // mMediaRecorder.getMaxAmplitude() 1~32767
 return maxlevel * mMediaRecorder.getMaxAmplitude() / 32768 + 1;
 } catch (Exception e) {
 }
 }
 return 1;
 }

 /**
 * 释放资源
 */
 public void release() {
 //mMediaRecorder.stop();
 mMediaRecorder.reset();
 mMediaRecorder = null;
 }

 /**
 * 取消录音
 */
 public void cancel() {
 release();
 if (mCurrentFilePath != null) {
 File file = new File(mCurrentFilePath);
 file.delete();
 mCurrentFilePath = null;
 }

 }

 public String getCurrentFilePath() {

 return mCurrentFilePath;
 }
}

AudioRecorderButton.java

package com.xuliugen.weichat;

import android.content.Context;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

import com.xuliugen.weichat.R;
import com.xuliugen.weichat.AudioManager.AudioStateListener;

public class AudioRecorderButton extends Button {

 private static final int STATE_NORMAL = 1;// 默认的状态
 private static final int STATE_RECORDING = 2;// 正在录音
 private static final int STATE_WANT_TO_CANCEL = 3;// 希望取消

 private int mCurrentState = STATE_NORMAL; // 当前的状态
 private boolean isRecording = false;// 已经开始录音

 private static final int DISTANCE_Y_CANCEL = 50;

 private DialogManager mDialogManager;
 private AudioManager mAudioManager;

 private float mTime;
 // 是否触发longClick
 private boolean mReady;

 private static final int MSG_AUDIO_PREPARED = 0x110;
 private static final int MSG_VOICE_CHANGED = 0x111;
 private static final int MSG_DIALOG_DIMISS = 0x112;

 /*
 * 获取音量大小的线程
 */
 private Runnable mGetVoiceLevelRunnable = new Runnable() {

 public void run() {
 while (isRecording) {
 try {
  Thread.sleep(100);
  mTime += 0.1f;
  mHandler.sendEmptyMessage(MSG_VOICE_CHANGED);
 } catch (InterruptedException e) {
  e.printStackTrace();
 }
 }
 }
 };

 private Handler mHandler = new Handler() {

 @Override
 public void handleMessage(Message msg) {
 switch (msg.what) {
 case MSG_AUDIO_PREPARED:
 // 显示對話框在开始录音以后
 mDialogManager.showRecordingDialog();
 isRecording = true;
 // 开启一个线程
 new Thread(mGetVoiceLevelRunnable).start();
 break;

 case MSG_VOICE_CHANGED:
 mDialogManager.updateVoiceLevel(mAudioManager.getVoiceLevel(7));
 break;

 case MSG_DIALOG_DIMISS:
 mDialogManager.dimissDialog();
 break;

 }

 super.handleMessage(msg);
 }
 };

 /**
 * 以下2个方法是构造方法
 */
 public AudioRecorderButton(Context context, AttributeSet attrs) {
 super(context, attrs);
 mDialogManager = new DialogManager(context);

 String dir = "/storage/sdcard0/my_weixin";
 //String dir = Environment.getExternalStorageDirectory()+"/my_weixin";

 mAudioManager = AudioManager.getInstance(dir);
 mAudioManager.setOnAudioStateListener(new AudioStateListener() {

 public void wellPrepared() {
 mHandler.sendEmptyMessage(MSG_AUDIO_PREPARED);
 }
 });

 // 由于这个类是button所以在构造方法中添加监听事件
 setOnLongClickListener(new OnLongClickListener() {

 public boolean onLongClick(View v) {
 mReady = true;

 mAudioManager.prepareAudio();

 return false;
 }
 });
 }

 public AudioRecorderButton(Context context) {
 this(context, null);
 }

 /**
 * 录音完成后的回调
 */
 public interface AudioFinishRecorderListener {
 void onFinish(float seconds, String filePath);
 }

 private AudioFinishRecorderListener audioFinishRecorderListener;

 public void setAudioFinishRecorderListener(AudioFinishRecorderListener listener) {
 audioFinishRecorderListener = listener;
 }

 /**
 * 屏幕的触摸事件
 */
 @Override
 public boolean onTouchEvent(MotionEvent event) {

 int action = event.getAction();
 int x = (int) event.getX();// 获得x轴坐标
 int y = (int) event.getY();// 获得y轴坐标

 switch (action) {
 case MotionEvent.ACTION_DOWN:
 changeState(STATE_RECORDING);
 break;
 case MotionEvent.ACTION_MOVE:

 if (isRecording) {
 // 如果想要取消,根据x,y的坐标看是否需要取消
 if (wantToCancle(x, y)) {
  changeState(STATE_WANT_TO_CANCEL);
 } else {
  changeState(STATE_RECORDING);
 }
 }

 break;
 case MotionEvent.ACTION_UP:
 if (!mReady) {
 reset();
 return super.onTouchEvent(event);
 }
 if (!isRecording || mTime < 0.6f) {
 mDialogManager.tooShort();
 mAudioManager.cancel();
 mHandler.sendEmptyMessageDelayed(MSG_DIALOG_DIMISS, 1000);// 延迟显示对话框
 } else if (mCurrentState == STATE_RECORDING) { // 正在录音的时候,结束
 mDialogManager.dimissDialog();
 mAudioManager.release();

 if (audioFinishRecorderListener != null) {
  audioFinishRecorderListener.onFinish(mTime,mAudioManager.getCurrentFilePath());
 }

 } else if (mCurrentState == STATE_WANT_TO_CANCEL) { // 想要取消
 mDialogManager.dimissDialog();
 mAudioManager.cancel();
 }
 reset();
 break;

 }
 return super.onTouchEvent(event);
 }

 /**
 * 恢复状态及标志位
 */
 private void reset() {
 isRecording = false;
 mTime = 0;
 mReady = false;
 changeState(STATE_NORMAL);
 }

 private boolean wantToCancle(int x, int y) {
 if (x < 0 || x > getWidth()) { // 超过按钮的宽度
 return true;
 }
 // 超过按钮的高度
 if (y < -DISTANCE_Y_CANCEL || y > getHeight() + DISTANCE_Y_CANCEL) {
 return true;
 }

 return false;
 }

 /**
 * 改变
 */
 private void changeState(int state) {
 if (mCurrentState != state) {
 mCurrentState = state;
 switch (state) {
 case STATE_NORMAL:
 setBackgroundResource(R.drawable.btn_recorder_normal);
 setText(R.string.str_recorder_normal);
 break;

 case STATE_RECORDING:
 setBackgroundResource(R.drawable.btn_recorder_recording);
 setText(R.string.str_recorder_recording);
 if (isRecording) {
  mDialogManager.recording();
 }
 break;

 case STATE_WANT_TO_CANCEL:
 setBackgroundResource(R.drawable.btn_recorder_recording);
 setText(R.string.str_recorder_want_cancel);

 mDialogManager.wantToCancel();
 break;
 }
 }
 }
}

DialogManager.java

package com.xuliugen.weichat;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.xuliugen.weichat.R;

/**
 * 用于管理Dialog
 *
 * @author xuliugen
 *
 */
public class DialogManager {

 private AlertDialog.Builder builder;
 private ImageView mIcon;
 private ImageView mVoice;
 private TextView mLable;

 private Context mContext;

 private AlertDialog dialog;//用于取消AlertDialog.Builder

 /**
 * 构造方法 传入上下文
 */
 public DialogManager(Context context) {
 this.mContext = context;
 }

 // 显示录音的对话框
 public void showRecordingDialog() {

 builder = new AlertDialog.Builder(mContext, R.style.AudioDialog);
 LayoutInflater inflater = LayoutInflater.from(mContext);
 View view = inflater.inflate(R.layout.dialog_recorder,null);

 mIcon = (ImageView) view.findViewById(R.id.id_recorder_dialog_icon);
 mVoice = (ImageView) view.findViewById(R.id.id_recorder_dialog_voice);
 mLable = (TextView) view.findViewById(R.id.id_recorder_dialog_label);

 builder.setView(view);
 builder.create();
 dialog = builder.show();
 }

 public void recording(){
 if(dialog != null && dialog.isShowing()){ //显示状态
 mIcon.setVisibility(View.VISIBLE);
 mVoice.setVisibility(View.VISIBLE);
 mLable.setVisibility(View.VISIBLE);

 mIcon.setImageResource(R.drawable.recorder);
 mLable.setText("手指上滑,取消发送");
 }
 }

 // 显示想取消的对话框
 public void wantToCancel() {
 if(dialog != null && dialog.isShowing()){ //显示状态
 mIcon.setVisibility(View.VISIBLE);
 mVoice.setVisibility(View.GONE);
 mLable.setVisibility(View.VISIBLE);

 mIcon.setImageResource(R.drawable.cancel);
 mLable.setText("松开手指,取消发送");
 }
 }

 // 显示时间过短的对话框
 public void tooShort() {
 if(dialog != null && dialog.isShowing()){ //显示状态
 mIcon.setVisibility(View.VISIBLE);
 mVoice.setVisibility(View.GONE);
 mLable.setVisibility(View.VISIBLE);

 mIcon.setImageResource(R.drawable.voice_to_short);
 mLable.setText("录音时间过短");
 }
 }

 // 显示取消的对话框
 public void dimissDialog() {
 if(dialog != null && dialog.isShowing()){ //显示状态
 dialog.dismiss();
 dialog = null;
 }
 }

 // 显示更新音量级别的对话框
 public void updateVoiceLevel(int level) {
 if(dialog != null && dialog.isShowing()){ //显示状态
// mIcon.setVisibility(View.VISIBLE);
// mVoice.setVisibility(View.VISIBLE);
// mLable.setVisibility(View.VISIBLE);

 //设置图片的id
 int resId = mContext.getResources().getIdentifier("v"+level, "drawable", mContext.getPackageName());
 mVoice.setImageResource(resId);
 }
 }

}

MainActivity.java

package com.xuliugen.weichat;

import java.util.ArrayList;
import java.util.List;

import com.xuliugen.weichat.AudioRecorderButton.AudioFinishRecorderListener;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class MainActivity extends Activity {
 private ListView mListView;

 private ArrayAdapter<Recorder> mAdapter;
 private List<Recorder> mDatas = new ArrayList<MainActivity.Recorder>();

 private AudioRecorderButton mAudioRecorderButton;

 private View animView;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 mListView = (ListView) findViewById(R.id.id_listview);
 mAudioRecorderButton = (AudioRecorderButton) findViewById(R.id.id_recorder_button);

 mAudioRecorderButton.setAudioFinishRecorderListener(new AudioFinishRecorderListener() {

 public void onFinish(float seconds, String filePath) {
 Recorder recorder = new Recorder(seconds, filePath);
 mDatas.add(recorder);
 mAdapter.notifyDataSetChanged(); //通知更新的内容
 mListView.setSelection(mDatas.size() - 1); //将lisview设置为最后一个
 }
 });

 mAdapter = new RecoderAdapter(this, mDatas);
 mListView.setAdapter(mAdapter);

 //listView的item点击事件
 mListView.setOnItemClickListener(new OnItemClickListener() {

 public void onItemClick(AdapterView<?> arg0, View view,int position, long id) {
 // 播放动画(帧动画)
 if (animView != null) {
  animView.setBackgroundResource(R.drawable.adj);
  animView = null;
 }
 animView = view.findViewById(R.id.id_recoder_anim);
 animView.setBackgroundResource(R.drawable.play_anim);
 AnimationDrawable animation = (AnimationDrawable) animView.getBackground();
 animation.start();
 // 播放录音
 MediaManager.playSound(mDatas.get(position).filePath,new MediaPlayer.OnCompletionListener() {

  public void onCompletion(MediaPlayer mp) {
  animView.setBackgroundResource(R.drawable.adj);
  }
  });
 }
 });
 }

 @Override
 protected void onPause() {
 super.onPause();
 MediaManager.pause();
 }

 @Override
 protected void onResume() {
 super.onResume();
 MediaManager.resume();
 }

 @Override
 protected void onDestroy() {
 super.onDestroy();
 MediaManager.release();
 }

 class Recorder {
 float time;
 String filePath;

 public Recorder(float time, String filePath) {
 super();
 this.time = time;
 this.filePath = filePath;
 }

 public float getTime() {
 return time;
 }

 public void setTime(float time) {
 this.time = time;
 }

 public String getFilePath() {
 return filePath;
 }

 public void setFilePath(String filePath) {
 this.filePath = filePath;
 }

 }

}

MediaManager.java

package com.xuliugen.weichat;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;

public class MediaManager {

 private static MediaPlayer mMediaPlayer;
 private static boolean isPause;

 /**
 * 播放音乐
 * @param filePath
 * @param onCompletionListener
 */
 public static void playSound(String filePath,OnCompletionListener onCompletionListener) {
 if (mMediaPlayer == null) {
 mMediaPlayer = new MediaPlayer();

 //设置一个error监听器
 mMediaPlayer.setOnErrorListener(new OnErrorListener() {

 public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
  mMediaPlayer.reset();
  return false;
 }
 });
 } else {
 mMediaPlayer.reset();
 }

 try {
 mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
 mMediaPlayer.setOnCompletionListener(onCompletionListener);
 mMediaPlayer.setDataSource(filePath);
 mMediaPlayer.prepare();
 mMediaPlayer.start();
 } catch (Exception e) {

 }
 }

 /**
 * 暂停播放
 */
 public static void pause() {
 if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { //正在播放的时候
 mMediaPlayer.pause();
 isPause = true;
 }
 }

 /**
 * 当前是isPause状态
 */
 public static void resume() {
 if (mMediaPlayer != null && isPause) {
 mMediaPlayer.start();
 isPause = false;
 }
 }

 /**
 * 释放资源
 */
 public static void release() {
 if (mMediaPlayer != null) {
 mMediaPlayer.release();
 mMediaPlayer = null;
 }
 }
}

RecoderAdapter.java

package com.xuliugen.weichat;

import java.util.List;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.xuliugen.weichat.MainActivity.Recorder;

public class RecoderAdapter extends ArrayAdapter<Recorder> {

 private Context mContext;
 private List<Recorder> mDatas;

 private int mMinItemWidth; //最小的item宽度
 private int mMaxItemWidth; //最大的item宽度
 private LayoutInflater mInflater;

 public RecoderAdapter(Context context, List<Recorder> datas) {
 super(context, -1, datas);

 mContext = context;
 mDatas = datas;

 //获取屏幕的宽度
 WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
 DisplayMetrics outMetrics = new DisplayMetrics();
 wm.getDefaultDisplay().getMetrics(outMetrics);
 mMaxItemWidth = (int) (outMetrics.widthPixels * 0.7f);
 mMinItemWidth = (int) (outMetrics.widthPixels * 0.15f);

 mInflater = LayoutInflater.from(context);
 }

 /**
 * 定义一个ViewHolder
 */
 private class ViewHolder {
 TextView seconds; // 时间
 View length; // 长度
 }

 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
 ViewHolder holder = null;
 if (convertView == null) {
 convertView = mInflater.inflate(R.layout.item_recoder, parent,false);
 holder = new ViewHolder();
 holder.seconds = (TextView) convertView.findViewById(R.id.id_recoder_time);
 holder.length = convertView.findViewById(R.id.id_recoder_lenght);

 convertView.setTag(holder);

 } else {
 holder = (ViewHolder) convertView.getTag();
 }
 holder.seconds.setText(Math.round(getItem(position).time) + "\"");
 ViewGroup.LayoutParams lp = holder.length.getLayoutParams();
 lp.width = (int) (mMinItemWidth + (mMaxItemWidth / 60f)* getItem(position).time);
 return convertView;
 }
}

本文已被整理到了《Android微信开发教程汇总》,欢迎大家学习阅读。

以上就是本文的全部内容,希望对大家的学习有所帮助。

(0)

相关推荐

  • android仿微信聊天界面 语音录制功能

    本例为模仿微信聊天界面UI设计,文字发送以及语言录制UI. 1先看效果图: 第一:chat.xml设计 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" andro

  • Android 高仿微信语音聊天页面高斯模糊(毛玻璃效果)

    目前的应用市场上,使用毛玻璃效果的APP随处可见,比如用过微信语音聊天的人可以发现,语音聊天页面就使用了高斯模糊效果. 先看下效果图: 仔细观察上图,我们可以发现,背景图以用户头像为模板,对其进行了高斯模糊,并把它作为整个页面的背景色. 关于Android如何快速实现高斯模糊(毛玻璃效果),网上一堆相关介绍,可参考下面文章一种快速毛玻璃虚化效果实现–Android. 下面直接给出模糊化工具类(已验证可行): import android.graphics.Bitmap; /** * 快速模糊化工

  • Android仿微信发送语音消息的功能及示例代码

    微信的发送语音是有一个向上取消的,我们使用onTouchListener来监听手势,然后做出相应的操作就行了. 直接上代码: //语音操作对象 private MediaPlayer mPlayer = null; private MediaRecorder mRecorder = null; //语音文件保存路径 private String FileName = null; FileName = Environment.getExternalStorageDirectory().getAbs

  • Android自定义UI实现微信语音

    本文实例为大家分享了java获取不同路径的方法,供大家参考,具体内容如下 思路: 自定义Button 获取DialogManager.AudioManager setOnLongClickListener长按事件--做好AudioManager的录音准备工作 AudioManager.setOnAudioStateListener(this)实现录音准备完毕的接口回调方法,方法中去发送MSG_AUDIO_PREPARE消息代表录音准备工作完毕 在mHandler中接收消息,开始开启线程录音,并且

  • Android仿微信语音聊天界面设计

    有段时间没有看视频了,昨天晚上抽了点空时间,又看了下鸿洋大神的视频教程,又抽时间写了个学习记录.代码和老师讲的基本一样,网上也有很多相同的博客.我只是在AndroidStudio环境下写的. --主界面代码-- public class MainActivity extends Activity { private ListView mListView; private ArrayAdapter<Recorder> mAdapter; private List<Recorder>

  • Android仿微信语音消息的录制和播放功能

    一.简述 效果: 实现功能: 长按Button时改变Button显示文字,弹出Dialog(动态更新音量),动态生成录音文件,开始录音: 监听手指动作,规定区域.录音状态下手指划出规定区域取消录音,删除生成的录音文件: 监听手指动作.当手指抬起时,判断是否开始录音,录音时长是否过短,符合条件则提示录音时长过短:正常结束时通过回调返回该次录音的文件路径和时长. 4.点击录音列表的item时,播放动画,播放对应的音频文件. 主要用到4个核心类: 自定义录音按钮(AudioRecordButton):

  • Android仿微信语音聊天功能

    本文实例讲述了Android仿微信语音聊天功能代码.分享给大家供大家参考.具体如下: 项目效果如下: 具体代码如下: AudioManager.java package com.xuliugen.weichat; import java.io.File; import java.io.IOException; import java.util.UUID; import android.media.MediaRecorder; public class AudioManager { private

  • Android仿微信语音对讲录音功能

    自微信出现以来取得了很好的成绩,语音对讲的实现更加方便了人与人之间的交流.今天来实践一下微信的语音对讲的录音实现,这个也比较容易实现.在此,我将该按钮封装成为一个控件,并通过策略模式的方式实现录音和界面的解耦合,以方便我们在实际情况中对录音方法的不同需求(例如想要实现wav格式的编码时我们也就不能再使用MediaRecorder,而只能使用AudioRecord进行处理). 效果图: 实现思路: 1.在微信中我们可以看到实现语音对讲的是通过点按按钮来完成的,因此在这里我选择重新自己的控件使其继承

  • Android仿微信QQ聊天顶起输入法不顶起标题栏的问题

    在这记录一下输入法弹出的一系列问题,有的输入法弹出就把整个布局弹上去,有的输入法弹出布局不会有变化,有的输入法弹出遮盖输入框等等问题,网上也有很多说加着加那的,但是看一下都不是很完整,解决不了所有问题,我在这归纳一下大家拿去用吧! *****先看看做好的效果图***** 一:AndroidManifest.xml里面对应的activity设置 android:windowSoftInputMode="adjustResize" 二:在activity的xml根布局设置 android:

  • android 仿微信demo——登录功能实现(移动端)

    移动端登录功能实现 登录功能基本和注册一样,唯一不同的是登录可以实现两种登录方式(微信号和手机号),也就是布局不一样.所以需要两个布局,两个activity(这个方法比较简单粗暴,我懒.也可以通过activity动态切换布局,这样只需要一个activity就可以了) 创建两个activity,实现两种登录方式 微信号登录activity LoginUser.java package com.example.wxchatdemo; import android.annotation.Suppres

  • android仿微信好友列表功能

    android studio实现微信好友列表功能,注意有一个jar包我没有放上来,请大家到MainActivity中的那个网址里面下载即可,然后把pinyin4j-2.5.0.jar复制粘贴到项目的app/libs文件夹里面,然后clean项目就可以使用了 实现效果图: (1)在build.gradle中引用第三方的类库 compile 'com.android.support:recyclerview-v7:26.0.0-alpha1' compile files('libs/pinyin4j

  • Android仿微信底部菜单栏功能显示未读消息数量

    底部菜单栏很重要,我看了一下很多应用软件都是用了底部菜单栏,这里使用了tabhost做了一种通用的(就是可以像微信那样显示未读消息数量的,虽然之前也做过但是layout下的xml写的太臃肿,这里去掉了很多不必要的层,个人看起来还是不错的,所以贴出来方便以后使用). 先看一下做出来之后的效果: 以后使用的时候就可以换成自己项目的图片和字体了,主框架不用变哈哈, 首先是要布局layout下xml文件 main.xml: <?xml version="1.0" encoding=&qu

  • android 仿微信demo——注册功能实现(移动端)

    移动端注册功能实现 微信的注册界面每一个文本段都有下划线且默认颜色都是灰色,当其中一个文本段获取焦点会将下划线的颜色变为绿色,而且文本输入框的光标也是绿色的,还有在文本输入框没有全部输入的情况下,按钮是不能点击的,只有当文本输入框全部输入的情况下才能点击且此时按钮会变成绿色.除了这些UI功能外,当点击注册按钮是还会把表单数据发送给服务器 创建activity Reigister.java activity Reigister.java package com.example.wxchatdemo

随机推荐