2017-06-29 28 views
0

我在第二個活動中有一個XML佈局,顯示基於用戶是否登錄的兩個LinearLayouts之一,以及TextView我從未顯示過文本在我看到佈局編輯器中的「設計」面板時,它確實呈現它正確TextView在設計預覽中顯示,但在實際的Android應用程序中不顯示

TextView在那裏(如果我設置背景顏色,它顯示顏色),但文本本身從不呈現。

點擊中開始LoginActivity,它具有onCreateMainActivity結果的按鈕(這是科特林):

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它說它無法找到隱藏密碼圖標的錯誤等) What Android Studio shows me

而這正是我的設備顯示
What I get on my device

編輯:我已經刪除的佈局文件的一切除TextView和父母LinearLayout它仍然沒有顯示。

+0

我試圖消除'TextInputLayout',看看是否真的是發現問題。雖然設計警告消失,但問題仍然存在 – Parker

+0

如果刪除此行'android:textAppearance =「@ android:style/TextAppearance.Material.Headline」/>',該怎麼辦? –

+0

不,剛剛嘗試過,實際上甚至將XML簡化爲「LinearLayout」和「TextView」 – Parker

回答

1

發現此問題。切換android:text="You're currently logged in"android:text="You\'re currently logged in"固定它。所以我猜Android在使用XML設置文本時需要轉義單引號?

通過使用佈局檢查工具,這表明作爲mText沒有價值

+0

是的,它的確如此。但林特應該抱怨它。 –

+0

嗯,沒有看到這個錯誤,只有問題是抱怨我硬編碼的字符串。我在Android Studio 3 Canary 4上,所以也許它只是越野車? – Parker

+1

或者Lint的配置可能不正確 - 您可以根據自己的意願對其投訴進行靜音。 –

相關問題