如何在android中实现自定义Gif键盘?
我想在自定义键盘上使用gif图像。有人能帮我实现自定义gif键盘吗?您可以按照本教程创建自定义键盘: 然后,在实现您自己的图像或gif时,通过添加扩展弹出窗口的类来创建一个自定义的弹出窗口,其中包含您的图像。看看这个答案:如何在android中实现自定义Gif键盘?,android,keyboard,gif,Android,Keyboard,Gif,我想在自定义键盘上使用gif图像。有人能帮我实现自定义gif键盘吗?您可以按照本教程创建自定义键盘: 然后,在实现您自己的图像或gif时,通过添加扩展弹出窗口的类来创建一个自定义的弹出窗口,其中包含您的图像。看看这个答案: 在键盘中添加一个具有唯一键码的键,该键将触发并显示弹出窗口。您可以按照本教程创建自定义键盘: 然后,在实现您自己的图像或gif时,通过添加扩展弹出窗口的类来创建一个自定义的弹出窗口,其中包含您的图像。看看这个答案: 在键盘中添加一个具有唯一键码的键,该键将触发并显示弹出窗
在键盘中添加一个具有唯一键码的键,该键将触发并显示弹出窗口。您可以按照本教程创建自定义键盘: 然后,在实现您自己的图像或gif时,通过添加扩展弹出窗口的类来创建一个自定义的弹出窗口,其中包含您的图像。看看这个答案:
在键盘中添加一个具有唯一键码的键,该键将触发并显示弹出窗口。您需要创建一个自定义的EditText类,如下所示
public class GifEditText extends EditText {
public GifEditText(Context context) {
super(context);
}
public GifEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GifEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
final InputConnection ic = super.onCreateInputConnection(editorInfo);
EditorInfoCompat.setContentMimeTypes(editorInfo,
new String[]{"image/gif"});
final InputConnectionCompat.OnCommitContentListener callback =
new InputConnectionCompat.OnCommitContentListener() {
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo,
int flags, Bundle opts) {
// read and display inputContentInfo asynchronously
if (BuildCompat.isAtLeastNMR1() && (flags &
InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
try {
inputContentInfo.requestPermission();
} catch (Exception e) {
return false; // return false if failed
}
}
// read and display inputContentInfo asynchronously.
// call inputContentInfo.releasePermission() as needed.
return true; // return true if succeeded
}
};
return InputConnectionCompat.createWrapper(ic, editorInfo, callback);
}
}
像这样使用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.test.GifEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Test gif" />
</LinearLayout>
有关更多详细信息,请参阅官方文档:
您需要创建这样的自定义EditText类
public class GifEditText extends EditText {
public GifEditText(Context context) {
super(context);
}
public GifEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GifEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
final InputConnection ic = super.onCreateInputConnection(editorInfo);
EditorInfoCompat.setContentMimeTypes(editorInfo,
new String[]{"image/gif"});
final InputConnectionCompat.OnCommitContentListener callback =
new InputConnectionCompat.OnCommitContentListener() {
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo,
int flags, Bundle opts) {
// read and display inputContentInfo asynchronously
if (BuildCompat.isAtLeastNMR1() && (flags &
InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
try {
inputContentInfo.requestPermission();
} catch (Exception e) {
return false; // return false if failed
}
}
// read and display inputContentInfo asynchronously.
// call inputContentInfo.releasePermission() as needed.
return true; // return true if succeeded
}
};
return InputConnectionCompat.createWrapper(ic, editorInfo, callback);
}
}
像这样使用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.test.GifEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Test gif" />
</LinearLayout>
有关更多详细信息,请参阅官方文档:
通过实现此功能,我获得了示例,我们可以简单地创建自定义gif键盘
我得到了这个示例,通过实现它,我们可以简单地创建自定义gif键盘
嗨,Rajesh谢谢你的回复,我想要一个这样的键盘Hi,Rajesh谢谢你的回复,我想要一个这样的键盘你需要创建一个自定义类来扩展EditText类,请参考我下面的答案@Gowthami它解决了吗@Gowthami你能实现这个吗?我也必须这样做。请帮助我。你需要为此创建一个扩展EditText类的自定义类,请参阅下面的回答@gowthamidit solve@Gowthami你能实现这个吗?我也必须这样做。请帮助我。我是Android的初学者。如果你有任何示例应用程序,请分享。我想创建相同类型的应用程序。非常感谢。我是Android的初学者。如果你有任何示例应用程序,请分享。我想创建相同类型的应用程序。非常感谢。