![](/img/trans.png)
[英]How to modify Android app UI via java when I created it using main.xml file?
[英]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
相同的文件夾中創建該文件。
除此之外,您還有一些錯誤:
setContentView(R.layout.main)
。android:id="@android:id/list
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.