我试图替换片段中的
TextView
,这些片段放置在FrameLayouts
中。因此,TextView
在设计中可见,但在虚拟设备上的应用程序中看不到。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="385dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".RegistrationContainerFragment"
android:orientation="vertical"
android:background="@drawable/auth_container_background"
android:elevation="8dp"
android:translationZ="4dp"
android:layout_marginHorizontal="15dp">
<FrameLayout
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/username_and_email_input_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/password_input_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/primary_button_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fontFamily="@font/montserrat_semibold_font"
android:textSize="14sp"
android:textColor="@color/text"
android:text="Forgot password?"/>
<FrameLayout
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/textAndLinkText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"/>
</LinearLayout>
import android.os.Bundle
import android.text.InputType
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
class LoginContainerFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_registration_container, container, false)
val fragmentManager: FragmentManager = childFragmentManager
val fragmentTransaction: FragmentTransaction = fragmentManager.beginTransaction()
val title = TitleFragment()
title.setShowBackArrow(true)
title.setTitleText("Log In")
fragmentTransaction.add(R.id.title, title)
val textInputFragment = InputFragment()
textInputFragment.setInputType(InputType.TYPE_CLASS_TEXT)
textInputFragment.setInputHint("Enter your email or username")
fragmentTransaction.add(R.id.text_input_container, textInputFragment)
val passwordInputFragment = InputFragment()
passwordInputFragment.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD)
passwordInputFragment.setInputHint("Enter your password")
fragmentTransaction.add(R.id.password_input_container, passwordInputFragment)
val primaryButtonFragment = PrimaryButtonFragment()
primaryButtonFragment.setButtonText("next")
fragmentTransaction.add(R.id.primary_button_container, primaryButtonFragment)
val lineFragment = LineFragment()
fragmentTransaction.add(R.id.line, lineFragment)
val textAndLinkFragment = TextWithLinkFragment()
textAndLinkFragment.setTextAndLinkText(
getString(R.string.dont_have_an_account),
getString(R.string.sign_in)
)
fragmentTransaction.add(R.id.textAndLinkText, textAndLinkFragment)
fragmentTransaction.commit()
return view
}
}
我试图将
TextView
放在 FrameLayout
内,但没有帮助。
之后我试图为此制作一个片段
TextView
,但不知何故我的应用程序没有启动而是崩溃了。
我也尝试使用一些标签,如
\<androidx.swiperefreshlayout.widget.SwipeRefreshLayout\>
,但没有帮助。
使用了text_input_container,但它不存在于您的布局中
fragmentTransaction.add(R.id.text_input_container, textInputFragment)