问题是,当我在EditText中输入文本时,ScrollView在我的活动中不工作,也不会滚动。
fun statusBarColor(activity: Activity) {
val window = activity.window
// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
// clear FLAG_TRANSLUCENT_STATUS flag:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
//window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
// finally change the color
//window.statusBarColor = ContextCompat.getColor(activity, R.color.colorPrimaryDark)
//window.setStatusBarColor(Color.TRANSPARENT);
}
//Manifest code on activity.
android:windowSoftInputMode="adjustResize">
发布于 2019-09-21 23:27:55
您可以使用CoordinatorLayout作为根目录,并在其中使用NestedScrolView。
CoordinatorLayout作为根用户响应键盘,并使用NestedScrollView的助手( NestedScrollView包含布局代码)将布局滚动到手机顶部。
将这一问题纳入透视观点
CoordinaterLayout > NestedScrolView > yourLayout
按照下面的代码更改布局XMl
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- rest of your layout xml code-->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
发布于 2022-04-26 16:55:18
getWindow().setBackgroundDrawableResource(R.drawable.iv_background);
将initViews()
设置为SignIn
活动,并使其透明:
<item name="colorPrimaryVariant">#00000000</item>
发布于 2022-04-26 22:56:23
您可以通过拥有一个活动和内容布局文件来实现这一点。从您的例子来看,我们可以使用activity_login和content_login。在本例中,我将假设您的活动名为LoginActivity.class
,因此请相应更新。
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".LoginActivity">
<include layout="@layout/content_user_profile" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
content_user_profile
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@color/color_white"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".LoginActivity"
tools:showIn="@layout/activity_login">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--Have all your layout here as scrollviews expect one child. You can replace LinearLayout above with constraintLayout for more flexibility and responsiveness.-->
</Linearlayout>
</androidx.core.widget.NestedScrollView>
特定活动的清单代码
<activity
android:name=".LoginActivity"
android:colorMode="wideColorGamut"
android:exported="true"
android:label="@string/title_activity_login"
android:theme="@style/..."
android:windowSoftInputMode="adjustPan" />
https://stackoverflow.com/questions/58046939
复制