0

我有一个活动,我想用它来在我的列表视图中打开意图,但是当它用作活动名称时,使用 StrawberryShake 在我的列表视图中看起来不太好有没有办法重命名为 android 中的活动名称添加空间以便在列表视图中它看起来像

示例 A

示例 B

示例 C

而不是

示例A

示例B

示例C

这是我的代码

// 列表中的示例项 static final String[] breakfood = { "Strawberry_Shake", };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(this, 
            android.R.layout.simple_list_item_1, breakfood));
    // Setting up the list array above

    }
// Setting the onlick listener so the array will open up activity
protected void onListItemClick(ListView lv, View v, int position, long id){
    super.onListItemClick(lv, v, position, id);
    String openbreakclass = breakfood[position];
    try{

    // Using the class name to open up the activity  from the previous array but its 
        //displaying the dash in the list
        Class selected = Class.forName("com.example.yummini."+ openbreakclass);
        Intent selectedIntent = new Intent(this, selected);
        startActivity(selectedIntent);
    }catch (ClassNotFoundException e){
        e.printStackTrace();
    }
}
4

1 回答 1

4

您一定是在谈论出现在 Activity 顶部的标签,您可以在 Manifest 中对其进行自定义

    <activity
        android:name=".MainActivity"
        android:icon="@drawable/icon_small"
        android:label="@string/MyActivityName">
    </activity>

然后在strings.xml

   <string name="MyActivityName">My Activity Name</string>

甚至你也可以像这样使用一些 html 标签

   <string name="MyActivityName"><b><i>My Activity Name</i></b></string>

@已弃用

或简单(但不推荐硬编码字符串,它会在应用程序的全球化中产生问题)

<activity
    android:name=".MainActivity"
    android:icon="@drawable/icon_small"
    android:label="My Activity Name">
</activity>

编辑 :

对于您的问题,您可以使用类似 DisplayText & ValueText Pair 或

在标签中添加活动名称,在文本字段中添加显示名称

或者你可以有一个额外的 TextViewVisibility="Gone"

于 2013-09-20T20:09:34.567 回答