2016-05-15 10 views
1

Ich habe eine Aktivität, die auf der leeren Aktivität basiert. Ich habe eine erhebliche Menge an Änderungen vorgenommen, aber ich habe den Aktivitätstitel nicht berührt. Ich habe jedoch bemerkt, dass der Titel jetzt das Wort "Weiß" zeigt. Ich habe eine zweite Aktivität, die das Wort weiß als Text einer Schaltfläche und einige Zeichenfolgenressourcen enthält, die das Wort auch enthalten. Ich bin mir jedoch nicht sicher, wie einige davon als Hauptbeschäftigungstitel angezeigt werden. Ich habe einige relevante Teile unten aufgeführt.Aktivitätstitel zeigt ungeraden Wert

Manifest

<?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> 

Strings

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

Aktivität onCreate Methode

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

Aktivität Layout-

<?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> 
Layout-

Dialog

<?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> 

Styles

<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. Ich bekomme auch regelmäßig Ressourcen Chaos, "Run" -> "Rebuild Projekt" hilft mir. 2. Sie haben auch vergessen, das Haupt-XML-Layout zu posten, in dem 'Toolbar' definiert ist. 3. Was erscheint in Titel, wenn Sie 'getActionBar() auskommentieren. SetTitle (" MyFirstApp ")'? –

+0

Ich habe diese Zeile eingefügt, um das Problem zu lösen. Es hat tatsächlich die App zum Absturz gebracht, was meiner Meinung nach auf etwas in der AppCompat-Version zurückzuführen ist. –

+0

Wenn Sie die Support-Bibliothek verwenden, müssen Sie getSupportActionbar() aufrufen. SetTitle() –

Antwort

-1

Per Artem Anweisungen Projekt neu.