我在第二個活動中有一個XML佈局,顯示基於用戶是否登錄的兩個LinearLayouts
之一,以及TextView
我從未顯示過文本在我看到佈局編輯器中的「設計」面板時,它確實呈現它正確TextView在設計預覽中顯示,但在實際的Android應用程序中不顯示
TextView
在那裏(如果我設置背景顏色,它顯示顏色),但文本本身從不呈現。
點擊中開始LoginActivity
,它具有onCreate
上MainActivity
結果的按鈕(這是科特林):
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.login_layout)
和佈局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
android:id="@+id/loggedOut"
android:padding="24dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/passName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="true"
android:hint="Username"
android:inputType="textCapCharacters" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/passPin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="true"
android:hint="PIN"
android:inputType="numberPassword" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/passSubmit"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/loggedIn"
android:visibility="visible"
android:padding="24dp">
<TextView
android:id="@+id/loggedInMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="You're currently logged in"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.Material.Headline" />
<Button
android:id="@+id/passLogout"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logout" />
</LinearLayout>
</FrameLayout>
這是Android的Studio顯示(這些錯誤是TextInputLayout
它說它無法找到隱藏密碼圖標的錯誤等)
編輯:我已經刪除的佈局文件的一切除TextView
和父母LinearLayout
它仍然沒有顯示。
我試圖消除'TextInputLayout',看看是否真的是發現問題。雖然設計警告消失,但問題仍然存在 – Parker
如果刪除此行'android:textAppearance =「@ android:style/TextAppearance.Material.Headline」/>',該怎麼辦? –
不,剛剛嘗試過,實際上甚至將XML簡化爲「LinearLayout」和「TextView」 – Parker