简体   繁体   English

在android上禁用软键盘不起作用。 供测试用

[英]disable soft keyboard on android not working. for testing

I've tried muliple ways to disable the softkeyboard from my test but isn't working. 我尝试了多种方法来禁用测试中的软键盘,但无法正常工作。

  1. added to my androidmanifest.xml 添加到我的androidmanifest.xml

      <activity android:name="com.photos.ui.activity.WelcomeActivity" android:windowSoftInputMode="stateHidden" /> 

    The activity is the name of the folders for the app (not my test script) 活动是应用程序文件夹的名称(不是我的测试脚本)

  2. added to my androidmanifest.xml 添加到我的androidmanifest.xml

     <LinearLayout android:focusable="true" android:focusableInTouchMode="true" 

    /> />

  3. placed this in my test and in my setup 放在我的测试和设置中

     EditText edtView=solo.getEditText(0); edtView.setInputType(InputType.TYPE_NULL); 
  4. tried 试过了

      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(solo.getEditText(0).getWindowToken(),0); 

but getSystemService is giving me an error. 但是getSystemService给我一个错误。 (undefined in my class) I'm not sure how to use these two commands (在我的课程中未定义)我不确定如何使用这两个命令

and I'm using 2.3 with a samsung exhibit II. 我将2.3与三星展览II配合使用。

right now I'm using: 现在我正在使用:

    hnm, what calls would I need to create the context object? right now im using:    private Context context;

private static Class<?> launcherActivityClass;
static{
        try {
                launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
        }
}

public TestMain() throws ClassNotFoundException {
    super(TARGET_PACKAGE_ID, launcherActivityClass);
}

public TestMain(String name) throws ClassNotFoundException {
    super(TARGET_PACKAGE_ID, launcherActivityClass);
    setName(name);
}

public TestMain(String name, Class<?> className) throws ClassNotFoundException {
    super(TARGET_PACKAGE_ID, className);
    setName(name);

}


private Solo solo;

 @Override  
protected void setUp() throws Exception {


        solo = new Solo(getInstrumentation(), getActivity());

    Log.v("setup","setup");



}

@Override
protected void tearDown() throws Exception {

        solo.finishOpenedActivities();
}   

Thanks. 谢谢。

getSystemService() is a method of Context so if the class that you are inside of when you are trying to call that is not a Context (Activity extends, and thus is a Context) then you'll need to put a reference and a dot in front of the method. getSystemService()是Context一种方法,因此,如果尝试调用时所在的类不是Context (活动扩展,因此 Context),则需要放置引用和点在方法的前面 How you need to do that depends on what type of structure you are trying to put those two lines into. 您需要怎么做取决于您试图将这两行放入哪种类型的结构中。 If you are still inside an Activity, but are currently in an inner class you can fix it by doing like this: 如果您仍在Activity中,但当前在一个内部类中,则可以通过以下方法进行修复:

YourActivityName.this.getSystemService();

if you are inside some other class then you'll need to have a way to pass a Context in to it so that you can call the method on the Context object that is passed to you (ie as a constructor parameter). 如果您在其他类中,则需要有一种将Context传递给它的方法,以便可以在传递给您的Context对象上调用该方法(即,作为构造函数参数)。

Edit: 编辑:

I think, You would want to be putting this code inside the WelcomeActivityI think, not inside of this test object. 我认为,您可能希望将此代码放入WelcomeActivity我认为的内部,而不是此测试对象的内部。 I can't tell based on what you've posted what you are trying to do all the way, but if you are deadset on doing it from that chunk of code my guess is that launcherActivityClass is going to be involved in obtaining the context. 我无法根据发布的内容一目了然,但是如果您对那段代码不满意,那么我猜是launcherActivityClass将参与获取上下文。 Are you inflating this into an Activity object? 您是否将此夸大为一个Activity对象? if so you can pass it through as a context without doing anything to it. 如果是这样,您可以将其作为上下文传递而无需执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM