How to keep background image size when software keyboard show

后端 未结 9 1685
一生所求
一生所求 2020-12-08 20:17

When the software keyboard shows, it resizes my layout and thus squeezes the background image together. My question is basically a duplicate of this question, which is expla

相关标签:
9条回答
  • 2020-12-08 21:05

    Maybe there's another (really simple!) solution: In styles.xml: create a new style like this:

    <style name="Yourstyle" parent="AppBaseTheme">
        <item name="android:windowBackground">@drawable/mybackground</item>
    </style>
    

    AppBaseTheme is your normally used theme for your app. Then you add in Manifest.xml:

    <activity 
        android:name="com.your.app.name.Activity"
        android:theme="@style/Yourstyle">
    </activity>
    

    So you have the same style but with a background.

    Important: don't set any backgrounds in your normal .xml file!

    It's my first post and I hope it helps and sorry for my English.

    0 讨论(0)
  • 2020-12-08 21:06

    I actually ran into a similar problem not too long ago. I stumbled upon the correct answer with a bit of work, though.

    In your android manifest for this project, attached to the specific activity that you are using, use the line android:windowSoftInputMode="adjustPan|stateVisible" in the activity tag.

    adjustPan basically means that your activity will not resize itself to fit the soft keyboard, and stateVisible means that the soft keyboard will show when requested (this can be stateAlwaysVisible, etc if necessary)

    source : Android Dev for Activity tags

    0 讨论(0)
  • 2020-12-08 21:09

    You can use the windowBackground property, which makes the drawable fit the whole screen. To do that you need to:

    1- Create a style:

    <style name="Background" parent="@android:style/Theme.NoTitleBar">
        <item name="android:windowBackground">@drawable/you_bg_drawable</item>
    </style>
    

    2- Set your activity style in the AndroidManifest.xml

    <activity
        android:name=".ui.your_activity"
        android:theme="@style/Background"/>
    
    0 讨论(0)
提交回复
热议问题