How to keep background image size when software ke

2020-02-03 05:18发布

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 explained in a very good way:

Software keyboard resizes background image on Android

However, that question was closed when they found a hack to solve it. I cannot use this hack. My entire layout is inside a ScrollView, and I need to be able to use this scrollview properly at all times. By using android:windowSoftInputMode="stateVisible|adjustPan" the user will not be able to scroll down and see the bottom of the screen while the keyboard is showing, since the layout will partly exist behind the keyboard. Thus the solution is unacceptable to me. Are there any better solutions out there?

Cheers,

9条回答
可以哭但决不认输i
2楼-- · 2020-02-03 06:16

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"/>
查看更多
干净又极端
3楼-- · 2020-02-03 06:17

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.

查看更多
霸刀☆藐视天下
4楼-- · 2020-02-03 06:20

in Androidmanifest in activity tag use:

<activity ... android:windowSoftInputMode="adjustPan" ></activity>

check Android Developer reference

查看更多
登录 后发表回答