java - Activity 标题显示奇数值

标签 java android android-activity layout title

我有一个基于空 Activity 的 Activity 。我对此进行了大量更改,但没有触及 Activity 标题。然而,我注意到标题现在显示了“白色”一词。我有第二个 Activity ,其中包含单词白色作为按钮的文本以及一些也包含该单词的字符串资源。但是,我不确定如何选择其中任何一个来显示为主要 Activity 标题。我在下面添加了一些相关部分。

list

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

Activity onCreate方法

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

Activity 布局

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

最佳答案

按照 Artem 的指示重建项目。

关于java - Activity 标题显示奇数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37236807/

相关文章:

android - 我想知道哪个 Activity 类将数据传递给另一个 Activity 类

java - 将 csv 文件读入二维数组

java - 在 Android 上进行 SHA1 加密?

java - 有没有一种方法可以在按下底部的按钮时使按钮不消失?

java - 如何防止在 Android Oreo 中的 dobleTap 上启动重复 Activity

java - 我可以通过检查主 Activity 的 onPause() 中的 isFinish() 来确定 Android 应用程序完成运行吗?

java - 绘画程序不使用并行数组来正确存储大小和颜色

android - 为什么我的 Android 设备上的路由表有两个几乎相等的条目(不同指标)?

java - 获取照片的 gps 位置

android - 如何在切换到另一个选项卡之前更新选项卡布局