GVKun编程网logo

Android:无法确定如何使用setImeActionLabel(无法确定用于安装程序的语言)

5

关于Android:无法确定如何使用setImeActionLabel和无法确定用于安装程序的语言的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于、androidEditTextinput

关于Android:无法确定如何使用setImeActionLabel无法确定用于安装程序的语言的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于、android EditText inputType 及 android:imeOptions=”actionDone”、Android java.lang.ClassCastException:无法将android.widget.RelativeLayout强制转换为android.widget.EditText、Android MediaProjection acquisitionLatestImage始终为ImageReader返回Null等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

Android:无法确定如何使用setImeActionLabel(无法确定用于安装程序的语言)

Android:无法确定如何使用setImeActionLabel(无法确定用于安装程序的语言)

我要做的是更改虚拟键盘上显示的默认“完成”标签。这是我尝试没有运气的尝试:

mSearchInput.setImeOptions(EditorInfo.IME_ACTION_DONE);mSearchInput.setImeActionLabel(getString(R.string.search_action_label), EditorInfo.IME_ACTION_DONE);

能干,但是,处理该按钮的点击,这一点:

mSearchInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {    @Override    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {        if (actionId == EditorInfo.IME_ACTION_DONE) {            performSearch();            return true;        }        return false;    }});

我现在不知道如何更改该按钮上的标签。

答案1

小编典典

imeActionLabel套标签上的全屏IME模式右上方出现的按钮(即,当您的手机处于横向)。如果要更改键盘右下角的按钮,可以将某些标志传递给imeOptions

据我所知,对于该按钮,您只能执行一组特定的操作(有关支持的标志的完整列表,请参见此处),但是由于您似乎想要一个搜索按钮,因此您所要做的就是稍作调整您的第一行并使用IME_ACTION_SEARCH

mSearchInput.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

请注意,该按钮的确切外观将取决于输入方法。默认的Android键盘显示搜索标志的放大镜,而触摸输入(HTC的键盘)似乎完全不知道该标志,仍然显示一个返回按钮。

" alt="">

">

 <application android:icon="@drawable/icon" android:label="@string/app_name"> 这句报错,不知道怎么修改啊,在线跪求大神解答啊。

android EditText inputType 及 android:imeOptions=”actionDone”

android EditText inputType 及 android:imeOptions=”actionDone”

一、android 软件盘事件响应
在android中,有时需要对EditText实现软件盘监听的场景。当android按下软键盘的时候,响应完成、发送、搜索或者其他事件。
Google 提供了 EditorInfo、 KeyEvent 的一些方法,能够实现我们需要的功能。详细可研究:EditorInfo.class 和 KeyEvent.class.
 
输入回车键隐藏输入键盘的方法:

如果布局中包含多个EditText,可以为每个EditText控件设置android:singleLine=”true”,弹出的软盘输入法中回车键为next,直到最后一个获取焦点后显示为Done。点击Done后,隐藏输入盘。将EditText的imeOptions属性设置android:imeOptions=”actionDone”,则不管是不是最后一个EditText,点击回车键即隐藏输入法。

监听Enter的事件,编写Enter的事件响应。设置文本框的OnKeyListener,当keyCode ==KeyEvent.KEYCODE_ENTER的时候,表明Enter键被按下,就可以编写自己事件响应功能了。

XML文件如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<EditText
          android:id= "@+id/editTextId"
          android:layout_width= "fill_parent"
          android:layout_height= "50dp"
          android:imeOptions= "actionDone"
          android:hint= "@string/task_new_one"
          android:textSize= "15sp"
          android:singleLine= "true"
          android:paddingLeft= "5dp"
          android:layout_gravity= "center"
          android:background= "@drawable/rectangle"
          android:inputType= "text"
          >
  </EditText>

  

 

把EditText的Ime Options属性设置成不同的值,Enter键上可以显示不同的文字或图案。
actionNone : 回车键,按下后光标到下一行
actionGo : Go,
actionSearch : 一个放大镜
actionSend : Send
actionNext : Next
actionDone : Done,隐藏软键盘,即使不是最后一个文本输入框

通过修改 android:imeOptions 来改变默认的键盘显示文本。常用的常量值如下:
  1. actionUnspecified  未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.效果:
  2. actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE 效果:
  3. actionGo 去往,对应常量EditorInfo.IME_ACTION_GO 效果:
  4. actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH 效果: 
  5. actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND 效果:
  6. actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT 效果:
  7. actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE 效果:
     
JAVA代码:
EditText inputText = (EditText) findViewById(R.id. editTextId);   
inputText.setImeOptions(EditorInfo.IME_ACTION_DONE);


添加监听事件:
private final EditText.OnEditorActionListener editorActionListener =
           new TextView.OnEditorActionListener() {
               @Override
               public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                   if (actionId == KeyEvent.ACTION_DOWN || actionId == EditorInfo.IME_ACTION_DONE) {
                       //业务代码
                       haoMent.createTest(Test.getId(), v.getText().toString());
                       UiUtils.hideSoftKeyboard(getApplicationContext(), haoTest.this);
                       v.setText("");
                       v.clearFocus();
                       handler.post(updateView);
                   }
                   return true;
               }
          };



但是,如果手机的输入法不是内置输入法,而是其他第三方输入法,那么可能会发生软件盘回车键无响应的问题。为了防止该类事情,则增加红色部分,响应的其KeyEvent。

这时候需要在代码中添加事件响应。

inputKey = (EditText) findViewById(R.id.contactSearch_editText);
inputKey.addTextChangedListener(watcher);

inputKey.setOnKeyListener(new View.OnKeyListener() {
@Override
  public boolean onKey(View v, int keyCode, KeyEvent event) {
    

  if (KeyEvent.KEYCODE_ENTER == keyCode && event.getAction() == KeyEvent.ACTION_DOWN) {
    handler.post(updateView);
    return true;
  }
  return false;
  }
});
//响应键盘内容
public TextWatcher watcher = new TextWatcher() {

  @Override
  public void beforeTextChanged(CharSequence charSequence, int i, int i2,int i3) {

  }

  @Override
  public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

  }

  @Override
  public void afterTextChanged(Editable editable) {

  handler.post(updateView);

  }
};


 
二、android 输入类型
根据要输入的内容展现相应的软件盘,可通过修改 android:inputType 来实现。
这是一些常用的输入类型。
android:inputType="none"--输入普通字符
android:inputType="text"--输入普通字符
android:inputType="textCapCharacters"--输入普通字符
android:inputType="textCapWords"--单词首字母大小
android:inputType="textCapSentences"--仅第一个字母大小
android:inputType="textAutoCorrect"--前两个自动完成
android:inputType="textAutoComplete"--前两个自动完成
android:inputType="textMultiLine"--多行输入
android:inputType="textImeMultiLine"--输入法多行(不一定支持)
android:inputType="textNoSuggestions"--不提示
android:inputType="textUri"--URI格式
android:inputType="textEmailAddress"--电子邮件地址格式
android:inputType="textEmailSubject"--邮件主题格式
android:inputType="textShortMessage"--短消息格式
android:inputType="textLongMessage"--长消息格式
android:inputType="textPersonName"--人名格式
android:inputType="textPostalAddress"--邮政格式
android:inputType="textPassword"--密码格式
android:inputType="textVisiblePassword"--密码可见格式
android:inputType="textWebEditText"--作为网页表单的文本格式
android:inputType="textFilter"--文本筛选格式
android:inputType="textPhonetic"--拼音输入格式
android:inputType="number"--数字格式
android:inputType="numberSigned"--有符号数字格式
android:inputType="numberDecimal"--可以带小数点的浮点格式
android:inputType="phone"--拨号键盘
android:inputType="datetime"
android:inputType="date"--日期键盘
android:inputType="time"--时间键盘


密码框属性 android:password="true"   让EditText显示的内容自动为星号,输入时内容会在1秒内变成*字样。
纯数字 android:numeric="true"      让输入法自动变为数字输入键盘,同时仅允许0-9的数字输入
仅允许 android:capitalize="haoTest"   仅允许接受输入haoTest,一般用于密码验证
android:editable="false"         设置EditText不可编辑
android:singleLine="true"        强制输入的内容在单行
android:ellipsize="end"         自动隐藏尾部溢出数据,一般用于文字内容过长一行无法全部显示时


转载: http://www.cnblogs.com/haochuang/p/3571754.html

Android java.lang.ClassCastException:无法将android.widget.RelativeLayout强制转换为android.widget.EditText

Android java.lang.ClassCastException:无法将android.widget.RelativeLayout强制转换为android.widget.EditText

单击按钮将我从一个活动带到另一个活动时,我在Android中收到以下异常(我是Android开发中的新手,因此可能不是最聪明的问题):

java.lang.classCastException: android.widget.RelativeLayout cannot be cast to android.widget.EditText

我试过几次清理项目,尝试过Android Tools中的Fix Project Properties选项,已经检查了xml中的错误,但似乎无法弄清楚.我不得不提到,在发生此异常之前,该按钮可以正常工作一段时间.

这是我的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/editCustomerPhone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".CustomerInfoActivity" >

<FrameLayout
    android:id="@+id/frameLayout1"
    android:layout_width="wrap_content"
    android:layout_height="250dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/ic_new_delivery" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Insert Customer Data:"
        android:textColor="@color/light_blue"
        android:textSize="20sp"
        android:text/>

</FrameLayout>

<EditText
    android:id="@+id/editCustomerName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView1"
    android:layout_alignBottom="@+id/textView1"
    android:layout_alignParentRight="true"
    android:ems="10"
    android:inputType="textPersonName"
    android:textColor="@color/light_blue" />

<Button
    android:id="@+id/submitInfoBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/editCustomerName"
    android:text="Submit Info"
    android:textColor="@color/light_red" 
    android:onClick="submitCustomerInfo"/>

<EditText
    android:id="@+id/editCustomerPhone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editCustomerName"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/TextView01"
    android:ems="10"
    android:inputType="phone"
    android:textColor="@color/light_red" >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/frameLayout1"
    android:text="Name:"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@android:color/background_light"
    android:textandroid:typeface="serif" />

<TextView
    android:id="@+id/TextView02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/editCustomerPhone"
    android:layout_marginTop="14dp"
    android:text="Email:"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@android:color/background_light"
    android:textandroid:typeface="serif" />

<EditText
    android:id="@+id/editCustomerEmail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/TextView02"
    android:layout_alignBottom="@+id/TextView02"
    android:layout_alignLeft="@+id/editCustomerPhone"
    android:layout_alignParentRight="true"
    android:ems="10"
    android:inputType="textEmailAddress"
    android:textColor="@color/light_green" />

<TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/TextView02"
    android:layout_below="@+id/editCustomerName"
    android:layout_marginTop="19dp"
    android:text="Phone:"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@android:color/background_light"
    android:textandroid:typeface="serif" />
@H_301_17@

这是我在活动中引发异常的onCreate方法:

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

    this.editMail = (EditText)findViewById(R.id.editCustomerEmail);
    this.editName = (EditText)findViewById(R.id.editCustomerName);
    this.editPhone = (EditText)findViewById(R.id.editCustomerPhone); // the exception points me here
}
@H_301_17@

解决方法:

您的代码说:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/editCustomerPhone"
@H_301_17@

editCustomerPhone是相对布局.

Android MediaProjection acquisitionLatestImage始终为ImageReader返回Null

Android MediaProjection acquisitionLatestImage始终为ImageReader返回Null

如何解决Android MediaProjection acquisitionLatestImage始终为ImageReader返回Null?

我正在编写简单的Screenshot应用程序,并为此使用MediaProjection + ImageReader。我使用some sample解决此任务。
当我单击“捕获”按钮时,我总是在日志消息中得到"image: NULL"

ImageReader.newInstance中,我将格式设置为ImageFormat.RGB_565。默认值为0x1,但是当我使用此值时,会显示警告消息:

必须是以下之一:ImageFormat.UNKNowN,ImageFormat.RGB_565, ImageFormat.YV12,ImageFormat.Y8,ImageFormat.NV16,ImageFormat.NV21, ImageFormat.YUY2,ImageFormat.JPEG,ImageFormat.DEPTH_JPEG, ImageFormat.YUV_420_888,ImageFormat.YUV_422_888, ImageFormat.YUV_444_888,ImageFormat.FLEX_RGB_888, ImageFormat.FLEX_RGBA_8888,ImageFormat.RAW_SENSOR, ImageFormat.RAW_PRIVATE,ImageFormat.RAW10,ImageFormat.RAW12, ImageFormat.DEPTH16,ImageFormat.DEPTH_POINT_CLOUD, ImageFormat.PRIVATE,ImageFormat.HEIC

我的问题:为什么 ImageReader 中的 Image 总是 Null ?以及如何正确解决?谢谢

我的代码:

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.ImageFormat;
import android.hardware.display.displayManager;
import android.hardware.display.Virtualdisplay;
import android.media.Image;
import android.media.ImageReader;
import android.media.projection.MediaProjection;
import android.media.projection.mediaprojectionmanager;
import android.os.Bundle;
import android.os.Environment;
import android.util.displayMetrics;
import android.util.Log;
import android.view.View;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = "test_t";

    private ImageReader mImageReader;
    private mediaprojectionmanager mmediaprojectionmanager;
    private Intent mCreateScreenCaptureIntent;
    private MediaProjection mMediaProjection;
    private Virtualdisplay mVirtualdisplay;

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

        View mBtnCapture = findViewById(R.id.btn_capture);
        mBtnCapture.setonClickListener(this);

        init();
    }

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

    @Override
    protected void onActivityResult(int requestCode,int resultCode,Intent data) {
        super.onActivityResult(requestCode,resultCode,data);
        mMediaProjection = mmediaprojectionmanager.getMediaProjection(resultCode,data);
        if (mMediaProjection != null) {
            startScreenCapture();
            takeCapture();
            stopScreenCapture();
        }
    }

    @Override
    public void onClick(View v) {
        startActivityForResult(mCreateScreenCaptureIntent,777);
    }

    private void init() {
        displayMetrics displayMetrics = getResources().getdisplayMetrics();
        mImageReader = ImageReader.newInstance(displayMetrics.widthPixels,displayMetrics.heightPixels,ImageFormat.RGB_565,2); // format 0x1

        mmediaprojectionmanager = (mediaprojectionmanager) getSystemService(MEDIA_PROJECTION_SERVICE);
        mCreateScreenCaptureIntent = mmediaprojectionmanager.createScreenCaptureIntent();
    }

    private void startScreenCapture() {
        if (mMediaProjection == null)
            return;

        displayMetrics displayMetrics = getResources().getdisplayMetrics();
        mVirtualdisplay = mMediaProjection.createVirtualdisplay(
                "ScreenCapture",displayMetrics.widthPixels,displayMetrics.densityDpi,displayManager.VIRTUAL_disPLAY_FLAG_AUTO_MIRROR,mImageReader.getSurface(),null,null);
    }

    private void stopScreenCapture() {
        if (mVirtualdisplay == null) {
            return;
        }
        mVirtualdisplay.release();
        mVirtualdisplay = null;
    }

    private void takeCapture() {
        Image image = mImageReader.acquireLatestimage();
        if (image == null) {
            Log.d(TAG,"image: NULL");
            return;
        }

        int width = image.getWidth();
        int height = image.getHeight();
        final Image.Plane[] planes = image.getPlanes();
        final ByteBuffer buffer = planes[0].getBuffer();
        int pixelStride = planes[0].getPixelStride();
        int rowStride = planes[0].getRowStride();
        int rowPadding = rowStride - pixelStride * width;
        Bitmap mBitmap = Bitmap.createBitmap(width + rowPadding / pixelStride,height,Bitmap.Config.ARGB_8888);
        mBitmap.copyPixelsFromBuffer(buffer);
        mBitmap = Bitmap.createBitmap(mBitmap,width,height);
        image.close();
        saveBitmapToFile(mBitmap);
    }

    private void saveBitmapToFile(Bitmap bitmap) {
        File directory = new File(Environment.getExternalStorageDirectory(),"SCREEN_TEMP");
        if (!directory.exists())
            directory.mkdirs();
        String name = "shot" + new SimpleDateFormat("yyyyMMddHHmmsss").format(new Date()) + "." + Bitmap.CompressFormat.PNG.toString();
        File file = new File(directory,name);
        try {
            if (!file.exists()) {
                file.createNewFile();
            }
            FileOutputStream out = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG,100,out);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printstacktrace();
        }
    }

    private void tearDownMediaProjection() {
        if (mMediaProjection != null) {
            mMediaProjection.stop();
            mMediaProjection = null;
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

今天的关于Android:无法确定如何使用setImeActionLabel无法确定用于安装程序的语言的分享已经结束,谢谢您的关注,如果想了解更多关于、android EditText inputType 及 android:imeOptions=”actionDone”、Android java.lang.ClassCastException:无法将android.widget.RelativeLayout强制转换为android.widget.EditText、Android MediaProjection acquisitionLatestImage始终为ImageReader返回Null的相关知识,请在本站进行查询。

本文标签: