2011-03-22 14 views
0

嗨,我有以下XML佈局如何讓根據TextView的標籤以便集中

 <Button android:id="@+id/signupButton" 
     android:layout_gravity="left" 
     android:layout_width="100sp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft = "10px" 
     android:layout_marginTop = "10px" 
     android:text="Sign-Up"/> 

    <TextView 
    android:id="@+id/accountlabel" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text = "Forgot password" 
    android:textColor = "#000000" 
    android:layout_marginLeft = "10px" 
    android:layout_marginTop = "10px" 
    android:textSize="15sp" 
    android:paddingLeft="3px" 
    android:paddingRight="3px" 
/>  

<Button 
      android:id="@+id/cancelButton" 
    android:layout_gravity="right" 
      android:layout_width="100sp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft = "10px" 
      android:layout_marginTop = "10px" 
      android:text="SignOut"/> 

</LinearLayout>  

我的問題是,焦點只到一個按鈕another.it不會去textview因爲我的文字是可點擊的,所以我也需要關注它。

我讀了幾個解決方案,如android:focusable =「true」在textview中添加,但它沒有奏效。

有人對此有任何解決方案。

感謝

回答

0

最簡單的解決方案是通過添加屬性,以使TextView的與空的背景按鈕:

android:background="@android:color/transparent" 

到XML。所以,你的TextView將成爲:

<Button 
    android:id="@+id/accountlabel" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text = "Forgot password" 
    android:textColor = "#000000" 
    android:layout_marginLeft = "10px" 
    android:layout_marginTop = "10px" 
    android:textSize="15sp" 
    android:paddingLeft="3px" 
    android:paddingRight="3px" 
    android:background="@android:color/transparent" 
/>  

你也可以,如果你要使用不同的狀態選擇添加一些反饋給用戶,當對象具有焦點使用的ImageButton。

在這種情況下,您可以使用不同狀態的選擇器創建一個XML文件,並將其作爲背景參考,而不是將背景設置爲透明。見ImageButton reference

0

只是把 機器人:可點擊= 「真」 在你的TECT觀點..你的TextView, 的

放ID和Android的大小找回ID和應用onclick事件......

可能是這個工作對你...

+0

我添加了android:clickable =「true」,並在setOnClickListener中獲得了它的事件。實際上,當我想通了,我的重點轉到textview,但它不顯示在用戶界面。由於按鈕在焦點時變爲橙色,但textview不會改變任何顏色,所以我們認爲焦點不在textview上。 – Rishi 2011-03-22 11:45:25

+0

有沒有辦法找到什麼時候texview獲得焦點並更改其背景色,以便在UI上反映出來,以便人們可以很容易地識別出textview已獲得焦點。 – Rishi 2011-03-22 11:46:27

+0

@Rishi只是considor現在textview作爲按鈕現在在類編碼textview可以應用像按鈕 – Siten 2011-03-22 13:27:47

相關問題