-
大小: 11KB文件類型: .java金幣: 1下載: 0 次發(fā)布日期: 2021-05-09
- 語言: Java
- 標(biāo)簽:
資源簡介
方便使用的評論工具類,而且能監(jiān)聽到小鍵盤消失事件,能返回小鍵盤的高度,追蹤評論位置。
代碼片段和文件信息
package?com.zhrt.dp.duanpian.liver_plugin.danmu;
import?android.app.Activity;
import?android.content.Context;
import?android.graphics.drawable.BitmapDrawable;
import?android.os.Handler;
import?android.os.Message;
import?android.view.Gravity;
import?android.view.View;
import?android.view.ViewTreeObserver;
import?android.view.WindowManager;
import?android.view.inputmethod.InputMethodManager;
import?android.widget.Button;
import?android.widget.EditText;
import?android.widget.ListView;
import?android.widget.PopupWindow;
import?com.zhrt.dp.duanpian.R;
/**
?*?用來顯示聊天的布局,同時防止小鍵盤彈出導(dǎo)致播放內(nèi)容高度的改變
?*?為了保證每次都能正確監(jiān)聽小鍵盤的彈出與消失。pop不能復(fù)用,每次都要new哦
?*?Created?by?Eleven?on?2016/9/21.
?*/
public?class?TalkPopWindow?{
????public?TalkPopWindow(Activity?activity?OnSendMessage?onSendMessage){
????????this.activity?=?activity;
????????this.onSendMessage?=?onSendMessage;
????}
????/**
?????*?因為使用場景不同,所以這里可以用style標(biāo)志來選取不同的布局,客官當(dāng)然可以傳id
?????*?@param?activity
?????*?@param?onSendMessage
?????*?@param?style
?????*/
????public?TalkPopWindow(Activity?activity?OnSendMessage?onSendMessage?int?style){
????????this.activity?=?activity;
????????this.onSendMessage?=?onSendMessage;
????????this.style?=?style;
????}
????//入?yún)?br/>????Activity?activity;
????OnSendMessage?onSendMessage;
????//業(yè)務(wù)引用
????EditText?et;//通用輸入器
????Button?bt;//通用發(fā)送按鈕
????PopupWindow?pw;//popWindow??當(dāng)然也可以換成dialog,popwindow:不會引起視頻的暫停等,但是沒有復(fù)制粘貼功能;dialog:會引起視頻的暫停,但是可以調(diào)起系統(tǒng)的復(fù)制粘貼功能
????int?style?=?0;//輸入部分樣式
????//View
????//兼容其他用途,設(shè)置syle
????View?view?=?null;//popView
????View?tempView?=?null;//輸入View的布局
????//邏輯屬性
????int?containerHeight?=?0;//tempView的高度:
????int?height?=?0;//布局的高度
????boolean?toShow?=?false;//是不是第一次嘗試顯示,與顯示機制有關(guān)
????int[]?location?=?new?int[2];
????/**
?????*?顯示pop
?????*/
????public?void?pop(){
????????dimiss();
????????toShow?=?true;
????????view?=?activity.getLayoutInflater().inflate(R.layout.pop_layoutnull);
????????pw?=?new?PopupWindow(view?WindowManager.LayoutParams.MATCH_PARENTWindowManager.LayoutParams.MATCH_PARENT);
????????if(style?==?0){//區(qū)分style
????????????et?=?(EditText)?view.findViewById(R.id.et_danmuEdit);
????????????bt?=?(Button)?view.findViewById(R.id.bt_sendDanmu);
????????????view.findViewById(R.id.danmutLinear).setVisibility(View.VISIBLE);
????????????view.findViewById(R.id.commentLinear).setVisibility(View.GONE);
????????????tempView?=?view.findViewById(R.id.danmutLinear);
????????}else{
????????????et?=?(EditText)?view.findViewById(R.id.commentEdit);
????????????bt?=?(Button)?view.findViewById(R.id.commentButton);
????????????view.findViewById(R.id.danmutLinear).setVisibility(View.GONE);
????????????view.findViewById(R.id.commentLinear).setVisibility(View.VISIBLE);
????????????tempView?=?view.findViewById(R.id.commentLinear);
????????}
????????tempView.measure(00);
????????containerHeight?=?tempView.getMeasuredHeight();//計算輸入布局的高度。
????????//監(jiān)聽布局的變化
????????view.getViewTreeObserver
評論
共有 條評論