簡體   English   中英

我在 main.xml 中設置的背景顏色在應用程序運行時未顯示

[英]The background color I'm setting in main.xml isn't showing when the app runs

我在 main.xml 中設置背景顏色。

當我在 Eclipse 中預覽布局時,背景顏色正確顯示,但當應用程序在我的設備上運行時,背景顏色默認為黑色。 應用程序運行時,我對 main.xml 的更改似乎都沒有反映出來。

這是我的 main.xml 文件

<?xml version="1.0" encoding="utf-8"?>

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lst"
android:layout_width="match_parent"
android:background="@color/listViewBG"
android:divider="@drawable/divider"
/>

這是主要活動中的 OnCreate

public class AleWorldActivity extends ListActivity
{
String classes[] = { "Movies", "Pictures" };

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(AleWorldActivity.this, android.R.layout.simple_list_item_1, classes));
}

有任何想法嗎? 謝謝

這是我的字符串.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello">Hello World, AleWorldActivity!</string>
<string name="app_name">Ale World</string>
<color name="listViewBG">#e101f5</color>

</resources>

凱文

您應該在colors.xml上聲明您的顏色。 在與strings.xml相同的文件夾中創建該文件。

除此之外,您還有一些錯誤:

  • 您缺少 AleWorldActivity 上的setContentView(R.layout.main)
  • 你的 ListView 的 id 是錯誤的。 將其更改為: android:id="@android:id/list
  • 在您的 ListView xml 中添加android:layout_height="wrap_content"

@color/listViewBG更改為#FFFFFF看看屏幕是否更改 colors 這意味着您在 strings.xml 中聲明它時出現問題。

http://developer.android.com/resources/samples/SoftKeyboard/res/values/colors.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM