2016-05-15 51 views
1

我有一个基于空活动的活动。我对此做了大量更改,但我没有触及活动标题。但是,我注意到标题现在显示“白色”这个词。我有第二个活动,其中包含单词white作为一个按钮的文本,以及一些包含该单词的字符串资源。不过,我不确定这些中的任何一个如何被挑选出来作为主要活动标题。我在下面列出了几个相关部分。活动标题显示奇数值

舱单

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.myfirstapp"> 

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.CAMERA"/> 
<uses-feature android:name="android.hardware.camera2" android:required="false"/> 

<application 
    android:debuggable="true" 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MyActivity" android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity android:name=".DisplayMessageActivity"></activity> 
    <activity android:name=".DisplayDialogTextProperties" 
       android:theme="@android:style/Theme.Dialog"/> 
</application> 

</manifest> 

字符串

<resources> 
<string name="app_name">MyFirstApp</string> 
<string name="edit_message">Enter Text</string> 
<string name="button_send">Apply Text</string> 
<string name="action_settings">Settings</string> 
<string name="open_gallery">Open Gallery</string> 
<string name="new_image">New Image</string> 
<string name="OK">OK</string> 
<string name="Cancel">Cancel</string> 
<string name="Red">Red</string> 
<string name="Blue">Blue</string> 
<string name="Green">Green</string> 
<string name="Black">Black</string> 
<string name="White">White</string> 
<string name="Yellow">Yellow</string> 
<string name="Text_Properties_Colour">Choose the text colour you require</string> 
<string name="Commit_Change">Commit Change</string> 
<string name="Revoke_Change">Remove Change</string> 

<!-- TODO: Remove or change this placeholder text --> 
<string name="hello_blank_fragment">Hello blank fragment</string> 

活动onCreate方法

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_my); 
    packageManager = getPackageManager(); 
    // getActionBar().setTitle("MyFirstApp"); 
} 
</resources> 

活动布局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin"> 
<!--tools:context="com.example.myfirstapp.MyActivity">--> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 

    android:id="@+id/text_bar" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="false"> 
    <!--app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/activity_my"--> 

    <EditText android:id="@+id/edit_message" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:hint="@string/edit_message" 
     android:enabled="false"/> 

    <Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/button_send" 
     android:onClick="applyTextToImage" 
     android:enabled="false" 
     android:id="@+id/overlayButton"/> 

</LinearLayout> 

<LinearLayout 
    android:id="@+id/buttons_Layout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="false" 
    android:gravity="bottom" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"> 

    <Button android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/open_gallery" 
      android:onClick="openGallery"> 
    </Button> 

    <Button android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/new_image" 
      android:onClick="newImage"> 
    </Button> 

</LinearLayout> 

<FrameLayout 
    android:id="@+id/image_Layout" 
    android:layout_below="@id/text_bar" 
    android:layout_above="@id/buttons_Layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
> 

    <ImageView 
     android:id="@+id/image_View" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
/> 
    <!--<TextView 
     android:id="@+id/image_Overlay" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:textAlignment="center" 
     android:textSize="25dp" 
     android:textColor="#ff0000"/>--> 
</FrameLayout> 

</RelativeLayout> 

对话框布局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

<TextView 
android:id="@+id/text_Properties" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_centerHorizontal="true" 
android:gravity="center_horizontal" 
android:text="@string/Text_Properties_Colour"/> 

<Button 
    android:id="@+id/choose_Blue" 
    android:layout_centerHorizontal="true" 
    android:layout_below="@id/text_Properties" 
    android:onClick="btn_Click" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/Blue"/> 

<Button 
    android:id="@+id/choose_Red" 
    android:layout_toLeftOf="@id/choose_Blue" 
    android:layout_below="@id/text_Properties" 
    android:onClick="btn_Click" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/Red"/> 

<Button 
    android:id="@+id/choose_Green" 
    android:layout_below="@id/text_Properties" 
    android:layout_toRightOf="@id/choose_Blue" 
    android:onClick="btn_Click" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/Green"/> 

<!--<TextView 
    android:id="@+id/center_Point" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/choose_Blue" 
    android:layout_centerHorizontal="true"/>--> 

<Button 
    android:id="@+id/choose_Black" 
    android:layout_below="@id/choose_Blue" 
    android:layout_centerHorizontal="true" 
    android:onClick="btn_Click" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/Black"/> 

<TextView 
    android:id="@+id/center_Point_Lower" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/choose_Black" 
    android:layout_centerHorizontal="true"/> 

<Button 
    android:id="@+id/CommitChanges" 
    android:onClick="commit_Click" 
    android:text="@string/Commit_Change" 
    android:layout_centerHorizontal="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/choose_Black" 
    android:layout_toLeftOf="@id/center_Point_Lower"/> 


<Button 
    android:id="@+id/choose_Yellow" 
    android:layout_below="@id/choose_Blue" 
    android:layout_toLeftOf="@id/choose_Black" 
    android:onClick="btn_Click" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/Yellow"/> 

<Button 
    android:id="@+id/choose_White" 
    android:layout_below="@id/choose_Blue" 
    android:layout_toRightOf="@id/choose_Black" 
    android:onClick="btn_Click" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/White"/> 

<Button 
    android:id="@+id/CancelChanges" 
    android:onClick="cancel_Click" 
    android:text="@string/Revoke_Change" 
    android:layout_centerHorizontal="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/choose_Black" 
    android:layout_toRightOf="@id/center_Point_Lower"/> 

</RelativeLayout> 

样式

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

</resources> 
+0

1.我也定期收到资源混乱,“运行” - >“重建项目”帮助我。 2.您还忘了发布主xml布局,其中定义了“工具栏”3.如果取消注释getActionBar()。setTitle(“MyFirstApp”)',Title中会显示什么? –

+0

我添加了该行来尝试解决问题。它实际上导致应用程序崩溃,我认为这是由AppCompat版本的使用所引起的。 –

+0

如果你使用支持库,你需要调用getSupportActionbar()。setTitle() –

回答

-1

按阿尔乔姆的指示重建项目。