在我的应用程序中,我想用普通字符和表情快捷键输入文本。
当在软键盘上输入字符时,我想用一系列图标/表情启动弹出菜单或弹出窗口。按下图标/表情符号将在光标处插入表情短距离字符。
有正常字符和表情-短切字符的文本是可以的。在文本中显示表情是进一步的一步。
发布于 2015-09-23 17:38:10
我喜欢的解决办法是:
1-单击笑脸按钮后,我启动弹出:
@Override
public void onClick(View v) {
switch( v.getId()) {
case R.id.fragment_log_popup_smileys:
PopupIcons popup = new PopupIcons( myActivity, new PopupIconResultHandler() {
@Override
public void iconClicked( String iconResult) {
logTextV.getText().insert( logTextV.getSelectionStart(), iconResult);
}
});
popup.show();
break;任何微笑字符都会插入到文本中。他们可以用同样的微笑来表现出来。这样做很容易。
2-弹出式窗口
public class PopupIcons implements Serializable {
Activity myActivity;
PopupIconResultHandler myClickHandler;
public PopupIcons( final Activity activityContext, PopupIconResultHandler clickHandler) {
myActivity = activityContext;
myClickHandler = clickHandler;
}
public void show() {
Rect rectgle= new Rect();
Window window= myActivity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame( rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop= window.findViewById( Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;
Display display = ((WindowManager) myActivity.getSystemService( Context.WINDOW_SERVICE)).getDefaultDisplay();
LinearLayout viewGroup = (LinearLayout) myActivity.findViewById( R.id.popupIconsLinearLayout);
LayoutInflater layoutInflater = (LayoutInflater) myActivity.getSystemService( Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate( R.layout.popup_icons, viewGroup);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow( myActivity);
popup.setContentView(layout);
popup.setFocusable(true);
popup.setAnimationStyle( R.style.PopupMenu);
popup.setWidth( FrameLayout.LayoutParams.WRAP_CONTENT);
popup.setHeight(FrameLayout.LayoutParams.WRAP_CONTENT);
View.OnClickListener handler = new View.OnClickListener() {
@Override
public void onClick( View v) {
if( myClickHandler != null) {
myClickHandler.iconClicked( (String) v.getTag());
}
popup.dismiss();
}
};
ImageButton but = (ImageButton) layout.findViewById( R.id.popup_icon_smile); but.setOnClickListener( handler);
but = (ImageButton) layout.findViewById( R.id.popup_icon_smile_big); but.setOnClickListener( handler);
but = (ImageButton) layout.findViewById( R.id.popup_icon_smile_cool); but.setOnClickListener( handler);
// etc ... for all buttons
popup.showAtLocation( layout, Gravity.BOTTOM | Gravity.LEFT, 30 , 30);
}}
我喜欢这种方法。你有改进的建议吗?
https://stackoverflow.com/questions/32010275
复制相似问题