简体   繁体   English

android 工作室中的编辑文本(SOFT_INPUT_ADJUST_PAN / SOFT_INPUT_ADJUST_RESIZE)

[英]editText in android studio (SOFT_INPUT_ADJUST_PAN / SOFT_INPUT_ADJUST_RESIZE)

在此处输入图像描述 The first picture is SOFT_INPUT_ADJUST_RESIZE.第一张图片是 SOFT_INPUT_ADJUST_RESIZE。 The screen does not go up, but the edittext is not visible.屏幕没有 go 起来,但是edittext是不可见的。

The second picture is for SOFT_INPUT_ADJUST_PAN.第二张图片用于 SOFT_INPUT_ADJUST_PAN。 The editText is visible, but the screen is cut off and raised. editText 是可见的,但屏幕被截断并升起。

How do I make the screen not cut and the edittext visible?如何使屏幕不被剪切并且edittext可见?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_chat);

    WindowManager.LayoutParams  layoutParams = new WindowManager.LayoutParams();
    layoutParams.flags  = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
    layoutParams.dimAmount  = 0.5f;
    getWindow().setAttributes(layoutParams);

    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int width = (int) (display.getWidth() * 0.85);
    int height = (int) (display.getHeight() * 0.85);
    getWindow().getAttributes().width = width;
    getWindow().getAttributes().height = height;

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);//or resize

Please do you have Full screen in style?请问你有全屏风格吗? like:喜欢:

<style name="AppTheme" 
parent="ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorMidBlue</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowFullscreen">false</item>
</style>

Or You are making your Activity Full screen at any place?或者您在任何地方都让您的活动全屏显示?

By Removing FLAG_FULLSCREEN from your code will solve your problem.通过从您的代码中删除 FLAG_FULLSCREEN 将解决您的问题。

you can add this line to your AndroidManifest.xml您可以将此行添加到您的 AndroidManifest.xml

android:windowSoftInputMode="adjustPan|adjustResize"

OR或者

also you can add it programmatically in java file like below您也可以在 java 文件中以编程方式添加它,如下所示

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

OR或者

You can also manage these things by using design layout in vertical scroll view so once user click on the edit text then the content of the page will be scroll vertically and you can see whole page.您还可以通过在垂直滚动视图中使用设计布局来管理这些内容,因此一旦用户单击编辑文本,页面的内容就会垂直滚动,您可以看到整个页面。

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

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