2011-07-20 15 views
-1

基本的には、メインインターフェイスでボタンの背景を変更したいと思っていますが、インテントからやりたいと思います。だから、例えば私はIDが「プロファイル」とのボタンがクリックされた場合に インテントからメインUIのアンドロイド変更ボタンバックグラウンド

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background" 
    > 

    <TableLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <TableRow 
      android:gravity="center" 
      android:layout_margin="20px"> 

      <Button 
       android:id="@+id/tunein" 
       android:layout_width="125px" 
       android:layout_height="125px" 
       android:gravity="center" 
       android:layout_margin="20px" 
       android:background="@drawable/tunein" 
       > 
      </Button> 

      <Button 
       android:id="@+id/settings" 
       android:layout_width="125px" 
       android:layout_height="125px" 
       android:gravity="center" 
       android:layout_margin="20px" 
       android:background="@drawable/settings"> 
      </Button> 
     </TableRow> 

     <TableRow 
      android:gravity="center" 
      android:layout_margin="20px"> 

      <Button 
       android:id="@+id/share" 
       android:layout_width="125px" 
       android:layout_height="125px" 
       android:gravity="center" 
       android:layout_margin="20px" 
       android:background="@drawable/sharing"> 
      </Button> 

      <Button 
       android:id="@+id/profile" 
       android:layout_width="125px" 
       android:layout_height="125px" 
       android:gravity="center" 
       android:background="@drawable/icon" 
       android:layout_margin="20px"> 
      </Button> 
     </TableRow> 

    </TableLayout> 

</LinearLayout> 

はその後、意図が現れ、このmain.xmlを持っており、それはからの画像とギャラリーが表示されますSDCARD、ユーザーは次のいずれかをクリックしたとき画像、 'プロフィール'ボタンの背景が変わります....

する方法... ???ボタンでヘルプ

答えて

0

のためのTHXのonclickあなたはちょうどそのギャラリーから戻った後、あなたはボタンで画像を配置することができ、そのイメージのパスから画像のパスを取得します

Button profile=(Button)findviewbyid(R.id.profile); 
profile.setOnclickListener(new OnClickListener(

public void onclick(View v) 
//call code for displaying images from gallery 
)); 

のように表示するには、ギャラリーの画像のためのコードを呼び出します

+0

それではできますか?私は、メインレイアウトの要素の1つを変更する意図があることを意味します....戻る場合は、イメージはデフォルトのイメージに戻されますか? – Jason

関連する問題