2013-12-12 19 views
0

我正在開發一款壁紙應用程序。隨着按鈕點擊圖像完美變化。我想顯示圖像的名稱或牆紙#1,然後到下一個和兒子,我想這個代替動作欄。我完全不知道它。我必須做的是(每次調用操作欄)或需要對imageview進行佈局。首先看看我的XML。我們如何在操作欄上調用壁紙名稱

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="fill" 
    android:orientation="vertical" 
    android:weightSum="100" > 
<ImageView 
    android:id="@+id/idImageViewPic" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="100" 
    android:adjustViewBounds="true" 
    android:background="#66FFFFFF" 
    android:maxHeight="91dip" 
    android:maxWidth="47dip" 
    android:padding="10dip" 
    android:src="@drawable/r0" /> 
<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 
<Button 
    android:id="@+id/bprev" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Back" > 
    </Button> 
<Button 
    android:id="@+id/bnext" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Next" > 
    </Button> 
     </LinearLayout> 
    </LinearLayout> 

這裏是主要活動。

public class Main extends Activity { 

    private ImageView hImageViewPic; 
    private Button iButton, gButton; 
    private int currentImage = 0; 

    int[] images = { R.drawable.r1, R.drawable.r2, R.drawable.r3, R.drawable.r4, R.drawable.r5, R.drawable.r6, R.drawable.r7, R.drawable.r8, R.drawable.r9, R.drawable.r10 }; 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    hImageViewPic = (ImageView)findViewById(R.id.idImageViewPic); 
    iButton = (Button) findViewById(R.id.bnext); 
    gButton = (Button) findViewById(R.id.bprev); 
     //Just set one Click listener for the image 
    iButton.setOnClickListener(iButtonChangeImageListener); 
    gButton.setOnClickListener(gButtonChangeImageListener); 
     } 
    View.OnClickListener iButtonChangeImageListener = new OnClickListener() { 
     public void onClick(View v) { 
     //Increase Counter to move to next Image 
     currentImage++; 
     currentImage = currentImage % images.length; 
     hImageViewPic.setImageResource(images[currentImage]); 
     } 
    }; 
     View.OnClickListener gButtonChangeImageListener = new OnClickListener() { 

     public void onClick(View v) { 
      //Increase Counter to move to next Image 
     currentImage--; 
     currentImage = currentImage % images.length; 
     hImageViewPic.setImageResource(images[currentImage]); 
     } 
    }; 
    } 

Plz給我解決方案來獲得這個目標。 Thanx

回答

0

你可以得到Hidden actionbar id。

抓住ID爲action_bar_title

int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android"); 

Now you can use the ID with a TextView 

TextView yourTextView = (TextView)findViewById(titleId); 
yourTextView.setTextColor(colorId); 
+0

thanx的答覆。先生,我把這個代碼放在Main_Activity中,但沒有結果。我對andriod很陌生。你能詳細介紹我嗎? – HBBR

+0

隨時歡迎。 – Harshid