【问题标题】:Avoid textField get focus - Android避免 textField 获得焦点 - Android
【发布时间】:2016-05-10 12:44:56
【问题描述】:

有没有办法避免在窗口加载时 textField 获得焦点? 我的 tiapp.xml 中有这个

 <android xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="stateHidden">
        <application android:theme="@style/Theme.CustomActionBar"/>
        <uses-sdk android:maxSdkVersion="23"
            android:minSdkVersion="14" android:targetSdkVersion="23"/>
    </manifest>
</android>

android:windowSoftInputMode 应该可以完成工作,但什么也没发生。 提前谢谢..

【问题讨论】:

  • 您需要针对屏幕执行此操作。 @Override protected void onResume() { super.onResume(); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);}
  • 感谢@Stallion,但我认为您的解决方案适用于原生 android 开发.. 对吗?

标签: android appcelerator textfield appcelerator-titanium


【解决方案1】:

试试这个模块:

https://github.com/mpociot/TiAndroidAutofocus

.................................................. .......

【讨论】:

  • 好吧,我试了一下,但第一次工作,当我第二次打开窗口时,应用程序崩溃了。
  • 是什么导致了崩溃?你有一些来自 LogCat 的崩溃日志吗?
【解决方案2】:

我认为android:windowSoftInputMode="stateHidden|adjustResize" 可以解决问题。

只需像这样在清单文件中定义您的 Activity。

<activity
        android:name="packagename.classname"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateHidden|adjustResize" >
</activity>

编码愉快。

【讨论】:

    【解决方案3】:

    解决此问题的一种可能方法是将以下布局添加到您的 XML:

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    
        <LinearLayout
            android:layout_width="0px"
            android:layout_height="0px"
            android:focusable="true"
            android:focusableInTouchMode="true"/>
    
        <AutoCompleteTextView
            android:id="@+id/autotext"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:nextFocusLeft="@id/autotext"
            android:nextFocusUp="@id/autotext"/>
    </LinearLayout>
    

    通过这样做,您的焦点将被移动到一个不可见的组件上。您可以创建一个布局并将其包含在您的主要 XML 中,使其更具可读性。

    【讨论】:

    • 感谢@edgar,但我认为您的回答是针对本机开发的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-30
    • 2012-09-25
    • 2021-08-24
    • 1970-01-01
    • 2020-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多