我们如何在动作栏上调用壁纸名称

时间:2013-12-12 08:59:50

标签: android android-actionbar

我正在开发一个壁纸应用程序。点击按钮,图像变化完美。我想显示图像的名称或作为壁纸#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给我解决方案来获得这个目标。感谢名单

1 个答案:

答案 0 :(得分:0)

您可以获取隐藏的操作栏ID。

抓取action_bar_title的ID

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);