a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 系統(tǒng) > Android > 正文

Android仿微信實現(xiàn)評論功能

2019-10-21 21:35:06
字體:
供稿:網(wǎng)友

在最近做的項目中有碰到要寫類似朋友圈的模塊,因為要實現(xiàn)評論點贊功能,這里說下我是怎么實現(xiàn)評論功能的。

首先先放上效果圖  

Android,微信,評論

這里貼上我的代碼:

//給評論圖標設(shè)置點擊事件 mIv_header_discuss.setOnClickListener(new View.OnClickListener() {  @Override  public void onClick(View v) {  showPopupcomment();  } });

showPopupcomment()方法如下

private PopupWindow popupWindow; private View popupView = null; private EditText inputComment; private String nInputContentText; private TextView btn_submit; private RelativeLayout rl_input_container; private InputMethodManager mInputManager; @SuppressLint("WrongConstant") private void showPopupcomment() { if (popupView == null){ //加載評論框的資源文件   popupView = LayoutInflater.from(context).inflate(R.layout.comment_popupwindow, null); } inputComment = (EditText) popupView.findViewById(R.id.et_discuss); btn_submit = (Button) popupView.findViewById(R.id.btn_confirm); rl_input_container = (RelativeLayout)popupView.findViewById(R.id.rl_input_container); //利用Timer這個Api設(shè)置延遲顯示軟鍵盤,這里時間為200毫秒 Timer timer = new Timer(); timer.schedule(new TimerTask() {  public void run()  {  mInputManager = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);  mInputManager.showSoftInput(inputComment, 0);  } }, 200); if (popupWindow == null){  popupWindow = new PopupWindow(popupView, RelativeLayout.LayoutParams.MATCH_PARENT,   RelativeLayout.LayoutParams.WRAP_CONTENT, false); } //popupWindow的常規(guī)設(shè)置,設(shè)置點擊外部事件,背景色 popupWindow.setTouchable(true); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000)); popupWindow.setTouchInterceptor(new View.OnTouchListener() {  @Override  public boolean onTouch(View v, MotionEvent event) {  if (event.getAction() == MotionEvent.ACTION_OUTSIDE)   popupWindow.dismiss();  return false;  } }); // 設(shè)置彈出窗體需要軟鍵盤,放在setSoftInputMode之前 popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED); // 再設(shè)置模式,和Activity的一樣,覆蓋,調(diào)整大小。 popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); //設(shè)置popupwindow的顯示位置,這里應(yīng)該是顯示在底部,即Bottom popupWindow.showAtLocation(popupView, Gravity.BOTTOM, 0, 0); popupWindow.update(); //設(shè)置監(jiān)聽 popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {  // 在dismiss中恢復(fù)透明度  @RequiresApi(api = Build.VERSION_CODES.CUPCAKE)  public void onDismiss() {  mInputManager.hideSoftInputFromWindow(inputComment.getWindowToken(), 0); //強制隱藏鍵盤  } }); //外部點擊事件 rl_input_container.setOnClickListener(new View.OnClickListener() {  @Override  public void onClick(View v) {  mInputManager.hideSoftInputFromWindow(inputComment.getWindowToken(), 0); //強制隱藏鍵盤  popupWindow.dismiss();  } }); //評論框內(nèi)的發(fā)送按鈕設(shè)置點擊事件 btn_submit.setOnClickListener(new View.OnClickListener() {  @Override  public void onClick(View v) {  nInputContentText = inputComment.getText().toString().trim();  if (nInputContentText == null || "".equals(nInputContentText)) {   showToastMsgShort("請輸入評論內(nèi)容");   return;  }  mInputManager.hideSoftInputFromWindow(inputComment.getWindowToken(),0);  popupWindow.dismiss();  } }); }

在剛開始顯示的時候發(fā)現(xiàn),EditText即評論框被頂?shù)狡聊蛔钌戏剑欢I盤顯示在底部,達不到效果。很多文章都說

popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

這兩句代碼順序不能變,然而這樣寫了之后還是實現(xiàn)不了,自己摸索了半天發(fā)現(xiàn)出現(xiàn)這樣的問題與評論框的布局也有關(guān)系。

所以在這里貼上我的評論框布局

R.layout.comment_popupwindow

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rl_input_container" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout  android:layout_width="match_parent"  android:layout_height="44dp"  android:background="@color/colorWhite"  android:layout_alignParentBottom="true"  android:orientation="horizontal">  <EditText  android:id="@+id/et_discuss"  android:layout_width="0dp"  android:layout_weight="1"  android:layout_height="38dp"  android:textColorHint="#a2a2a2"  android:textSize="13sp"  android:layout_marginRight="7dp"  android:layout_marginLeft="15dp"  android:layout_marginBottom="6dp"  android:layout_marginTop="6dp"  android:ellipsize="end"  android:background="@drawable/round_edittext_input"  android:layout_gravity="center_vertical"  android:paddingLeft="@dimen/ten_padding"  android:paddingRight="@dimen/ten_padding"  android:singleLine="true" />  <Button  android:id="@+id/btn_confirm"  android:text="發(fā)送"  android:background="@drawable/btn_discuss_bg"  android:textSize="16sp"  android:layout_gravity="center_vertical"  android:textColorHint="#b7b7b7"  android:textColor="@color/colorWhite"  android:layout_marginRight="@dimen/ten_padding"  android:gravity="center"  android:layout_width="40dp"  android:layout_height="38dp"/>  </LinearLayout></RelativeLayout>

把評論框和發(fā)送按鈕用LinearLayout包裹,然后在最外層用一個RelativeLayout包裹住,發(fā)現(xiàn)這樣子評論框就會和軟鍵盤一起彈出來了。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 97国产精品视频人人做人人爱 | 中文精品一区二区三区 | 超碰日韩在线 | 精品三级在线 | 狠狠色 综合色区 | 国产高清无密码一区二区三区 | 日韩av在线影院 | 欧美日韩在线精品 | 无遮挡又黄又刺激的视频 | 亚洲精品久久久日韩美女极品合集下载 | 国产小视频一区二区 | 青青草视频免费观看 | 成人黄色在线 | 日韩大片在线观看 | 亚洲精品一二三 | 亚洲成色www久久网站瘦与人 | 国产高潮好爽受不了了夜色 | 91精品国产91久久久久久吃药 | 国产精品日韩 | 一区高清 | 一级黄色录像免费观看 | 亚洲成人av| 中文av网站 | 国产精品久久久久久久久 | 久久久久中文字幕 | 午夜理伦三级 | 欧美日韩精品久久久久 | 一级人爱视频 | 日本一区二区免费在线 | 亚洲精品一区中文字幕乱码 | 国产日韩欧美一区二区 | 久久男人天堂 | 欧美一区不卡 | 毛片在线视频 | 国产精品久久久久久吹潮 | 91视频三区| 欧美日本久久 | 午夜国产精品视频 | 免费黄色av | 一区二区三区免费网站 | 北条麻妃一区二区在线 |