Xamarin.Android -- EditText输入无法实时显示问题

参考文章:EditText输入内容不显示_edittext输入没有显示-CSDN博客

https://blog.csdn.net/guodashen007/article/details/108768508


scrollview内嵌tablelayout布局,tablerow内嵌 EditText,EditText输入后文字不显示,因为安卓9以上会出现不兼容问题,后在配置文件增加硬件加速属性解决。EditText太靠手机边框导致内容看不到,或TextView出现这种情况,设置padding


在Android 9(API级别28)及以上版本中,某些布局和视图可能会因为系统默认的窗口背景绘制行为而出现不兼容问题。这可能会影响EditText和TextView的显示,尤其是当它们位于ScrollView或TableLayout中时。为了解决这个问题,你可以尝试以下步骤:

1.
设置ScrollView的背景:
为ScrollView设置一个背景色,这样可以确保滚动视图的背景不会影响到内部EditText或TextView的显示。
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"> <!-- 或者其他颜色 -->
    <!-- 内部布局 -->
</ScrollView>

 

2.
为EditText设置padding:
为EditText设置适当的padding,确保它们的内容不会被边缘裁剪。你可以根据需要调整padding的大小。
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp" />

 

3.
       <LinearLayout
           android:orientation="vertical"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
        android:descendantFocusability="beforeDescendants"
     android:hardwareAccelerated= "true"
       >

使用android:descendantFocusability属性:
在LinearLayout中添加android:descendantFocusability="beforeDescendants"属性,这样可以确保NestedScrollView不会拦截子视图的焦点事件。 在布局中加上 android:descendantFocusability="beforeDescendants" android:hardwareAccelerated= "true"

 


在配置文件中开启硬件加速:
对于特定的Activity:
HardwareAccelerated 开启硬件加上true
[Activity(
HardwareAccelerated = true,
WindowSoftInputMode = SoftInput.StateHidden | SoftInput.StateAlwaysHidden | SoftInput.AdjustPan | SoftInput.AdjustUnspecified | SoftInput.AdjustResize
)]
public class ActivityCheckPackage : Activity

  

posted @ 2024-07-12 11:53  LuoCore  阅读(2)  评论(0编辑  收藏  举报