2011-06-10 4 views
1

すべてのアクティビティーで共通のヘッダーがあります。実行時にヘッダーボタンのイメージとヘッダーテキストを変更する

header.xml異なる活動におけるしかし

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/header_layout" android:layout_width="fill_parent" 
android:layout_height="wrap_content" android:orientation="horizontal"> 

<!-- home button --> 
<ImageButton android:id="@+id/header_home_button" 
    android:src="@drawable/menu_info" android:layout_height="wrap_content" 
    android:layout_width="wrap_content" /> 

<!-- header text --> 
<TextView android:id="@+id/header_title" android:layout_width="200dip" 
    android:layout_height="wrap_content" android:gravity="center" 
    android:text="Todays recipe :" android:textSize="20dp" 
    android:textStyle="bold" /> 

</LinearLayout> 

IMAGEBUTTONためのTextViewや画像のタイトルの変更も変更されます。実行時にそれらを変更するには?

おかげ

答えて

0

あなただけの自分のIDでボタンとのTextViewの両方を取得し、あなたの活動から画像やテキストを設定する必要があります。

ImageButton _home = (ImageButton)finndViewById(R.id.header_home_button); 
_home.setImageResource(R.drawable.anyimage); 


TextView _title = (TextView)finndViewById(R.id.header_title); 
_title.setText("Your title"); 
0

あなたのアクティビティファイルでこれを使用します。

TextView tv_edit = (TextView)findViewByID(R.id.header_title); 
ImageButton btn_image = (ImageButton)findViewByID(R.id.header_home_button); 

tv_edit.settext("Your text"); 
btn_imagesetImageResource(R.id.myImage); 
関連する問題