У меня есть прозрачная активность с темой, которая содержит:
<item name="android:windowIsFloating">true</item>
Манифест:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="something.com">
<application android:hardwareAccelerated="true">
<activity
android:name=".flow.Activity"
android:windowSoftInputMode="adjustPan"
android:theme="@style/TransparentTheme" />
</application>
</manifest>
GenericFragment:
abstract class GenericFragment<V: MviView<VS>, VS, P: MviPresenter<V, VS>>: BaseFragment<V, VS,P>() {
abstract val layoutRes: Int
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val genericView = inflater.inflate(R.layout.generic_layout, container, false)
inflater.inflate(layoutRes, genericView.genericContent, true)
return genericView
}
}
Макет GenericFragment - generic_layout.xml:
<android.support.constraint.ConstraintLayout
android:background="@color/colorBlack12"
android:layout_height="match_parent"
android:layout_width="match_parent"
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.support.constraint.ConstraintLayout
android:background="@drawable/bg_fragment_generic"
android:elevation="5dp"
android:layout_height="0dp"
android:layout_width="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent=".8"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent=".50"
>
<TextView
android:id="@+id/title"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_width="wrap_content"
android:textAppearance="@style/Title"
app:layout_constraintBottom_toTopOf="@id/subtitle"
app:layout_constraintEnd_toEndOf="@+id/genericContent"
app:layout_constraintStart_toStartOf="@+id/genericContent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title"
/>
<TextView
android:id="@+id/subtitle"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_width="wrap_content"
android:textAppearance="@style/SubTitle"
app:layout_constraintEnd_toEndOf="@+id/genericContent"
app:layout_constraintStart_toStartOf="@+id/genericContent"
app:layout_constraintTop_toBottomOf="@+id/title"
tools:text="Subtitle"
/>
<Button
style="@style/Button.Action"
android:id="@+id/actionButton"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_width="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/genericContent"
tools:text="Action"
/>
<FrameLayout
android:id="@+id/genericContent"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_width="0dp"
app:layout_constraintBottom_toTopOf="@+id/actionButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/subtitle"
/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
Макет фрагмента входа - фрагмент_login.xml:
<android.support.constraint.ConstraintLayout
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.constraint.Group
android:id="@+id/loadingGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids=",loadingProgressBar"
/>
<android.support.constraint.Group
android:id="@+id/formGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
app:constraint_referenced_ids=",usernameEditText,passwordEditText"
/>
<something.com.ui.widget.CustomEditText
android:id="@+id/usernameEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Username"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/passwordEditText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
style="@style/Widget.AppCompat.EditText"
/>
<something.com.ui.widget.CustomEditText
android:id="@+id/passwordEditText"
style="@style/Widget.AppCompat.EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/usernameEditText"
/>
<ProgressBar
android:id="@+id/loadingProgressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordEditText"
tools:visibility="visible"
/>
<TextView
android:id="@+id/errorTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:textColor="#FF0000"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordEditText"
app:layout_constraintWidth_default="wrap"
tools:text="error"
tools:visibility="visible"
/>
</android.support.constraint.ConstraintLayout>
Реализация фрагмента входа не важна, LoginFragment наследует от GenericFragment и layoutRes = фрагмент_login.xml.
У меня проблема, когда открывается мягкая клавиатура. Когда windowIsFloating имеет значение true в стиле темы, содержимое фрагмента входа сворачивается, см. Экран . При значении windowIsFloating в стиле темы макет работает так, как я ожидал см. Экран - ожидается , но активность не прозрачна. Я хотел бы иметь прозрачную активность с и также работает Android: WindowSoftInputMode = "AdjustPan".
Спасибо за помощь.