![](/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.