2014-03-30 71 views
0

我在Eclipse Android应用程序中有5个布局视图。我想在所有图形布局中显示不同的布局标题和标题图标图像(位于左上角),而不是以编程方式显示。Android:如何设置不同的布局标题和标题栏图标图像

目前,它在所有布局中显示相同的应用标题,并在所有视图中显示应用图标图像。

<application android:name="singleton" 
    android:allowBackup="true" 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 

我试过登录活动标题标签如下,login_name已经添加到字符串中:但是,这里没有显示任何标题。

<activity 
     android:name="com.example.myappandroid.LoginActivity" 
     android:label="@string/login_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

请指教,如何解决这个问题通过图形化布局?

+0

什么样的布局?活动?请注意,“操作栏”(标题和图标的显示位置)属于一个活动。因此,通过XML,您只能在/上指定文本。如果您需要在活动中间更改标题/图标,则必须以编程方式进行。但它非常简单,只需getActionBar()。setTitle(“hi”)将在活动级别执行此操作,或者在任何视图级别执行((Activity)getContext())。getActionBar()。setTitle()。或者你可以定义不同的活动,每个不同的布局,图标和标题 – rupps

+0

谢谢!我试过this.setTitle(“Login”);这是工作。 – Stella

+0

非常好! :)请注意,如果你做this.getActionBar()。 ...您可以在动作栏中更改更多内容:图标,颜色等... – rupps

回答

0

你是否说你想在操作栏上自定义图标和标题?如果是,那么我会提及我为此所做的... 1.首先我创建一个自定义xml文件 2.ActionBar actionBar = getActionBar(); actionBar.setCustomView(R.layout.action_bar); //使用它来加载你自己的操作条 actionBar.setDisplayShowCustomEnabled(true);

0

清楚我在我的项目最近确实是..

<?xml version="1.0" encoding="utf-8"?>//first i created a xml file for the ui i need 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/TopBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#E6E7E9" > 

    <ImageButton 
     android:id="@+id/baricon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:background="@null" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 

ActionBar actionBar=getActionBar();// then i call this part in my activity 
actionBar.setCustomView(R.layout.action_bar); 
actionBar.setDisplayShowCustomEnabled(true); 
enter code here