2016-07-22 39 views
0

我在活动中有一个页脚。这个页脚包含。在edittext下面放置一个edittext和一个radiogroup。几乎像页脚页脚。 基本上我使用radiogroup来选择键盘类型(表情符号键盘或普通键盘)。 xml在下面。带脚注的editdtext。当edittext获得焦点时,脚本在softinputkeyboard下消失

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_gravity="bottom"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/textbase_layout" 
     android:background="@color/appwhite"> 
     <View 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:background="@color/window_background" 
      android:layout_alignParentTop="true" /> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:maxHeight="80dp" 
      android:id="@+id/comment_txt" 
      android:layout_marginTop="8dp" 
      android:textColorHint="@color/comment_header_grey" 
      android:hint="message goes here" 
      android:background="@android:color/transparent" 
      android:padding="5dp" 
      android:focusable="true" 
      android:layout_marginLeft="10dp" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="10dp" /> 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/appwhite" 
     android:layout_below="@id/textbase_layout"> 
     <RadioGroup 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      android:orientation="horizontal"> 
      <RadioButton 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:id="@+id/keyboard_btn" 
       android:padding="8dp" 
       android:textColor="@drawable/selector_text_radio" 
       android:button="@drawable/keyboard_icon_selector" 
       android:layout_marginRight="5dp" /> 
      <RadioButton 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:id="@+id/emoji_btn" 
       android:padding="8dp" 
       android:textColor="@drawable/selector_text_radio" 
       android:button="@drawable/smiley_icon_selector" 
       android:layout_marginLeft="5dp" /> 
     </RadioGroup> 
     <Button 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:id="@+id/send_btn" 
      android:text="Send" 
      android:textColor="@color/bcg_blue" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:background="@android:color/transparent" /> 
    </RelativeLayout> 
</RelativeLayout> 

我有WindowSoftInputMode = SoftInput.AdjustResize set也。当我选择edittext时,我希望整个页脚都被推上去。包括radiogroup。但在某些情况下,这不会发生。底部的radiogroup正在被软键盘切断。当我在我的oncreate()方法中执行这一行时。

Window.SetSoftInputMode(SoftInput.StateAlwaysHidden); 

如果我注释掉上面的行。该radiogroup总是显示,但它创造了一个不同的不受欢迎的条件,因为当第一次打开活动时软键盘会弹出。 在这种情况下,我试图从edittext中移除焦点,但softkeyboard在进入活动时仍然弹出。如果任何人有任何想法如何解决这个问题,将不胜感激。

+0

当显示键盘时,android只会推动直到焦点处的控件。您的单选按钮是布局中的单独控件,它们不会被推到键盘上。您可能想要使用编辑控件左侧的切换按钮,就像大多数聊天应用程序用于更改键盘类型一样。 – chejaras

回答

1

使用下面的代码来更改您的清单xml ,,对于哪个xml布局包含活动。

机器人:windowSoftInputMode = “stateUnchanged | adjustResize”

OR

机器人:windowSoftInputMode = “adjustPan | adjustResize” 清单文件

变化

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.adjustscroll.MainActivity" 
     android:label="@string/app_name" 
     android:windowSoftInputMode="stateUnchanged|adjustResize" 
     > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

希望这将有助于您。让我知道如果解决。

+0

不知道如何将多个参数传递给xamarin中的windowsoftinputmode? –

+0

我认为防止入口上的键盘弹出而不必使用Window.SetSoftInputMode(SoftInput.StateAlwaysHidden);将修复该方法工作的问题 –

+0

。干杯 –