更改android应用程序的布局颜色
我正在尝试编写一个程序,将屏幕的背景颜色更改为我决定的颜色。 我写了一些类似的东西,但当它运行时崩溃了 有什么问题,请帮助我。这是xml代码更改android应用程序的布局颜色,android,android-layout,layout,background,Android,Android Layout,Layout,Background,我正在尝试编写一个程序,将屏幕的背景颜色更改为我决定的颜色。 我写了一些类似的东西,但当它运行时崩溃了 有什么问题,请帮助我。这是xml代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientatio
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="#FFFFFF"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Green" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue" />
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="White" />
</LinearLayout>
</LinearLayout>
您没有将
视图
变量分配给任何对象,这可能会导致代码中出现NullPointerException
尝试在XML文件中的线性布局下添加此行:
android:id=“@+id/view”
并将此行添加到您的onCreate
:
view=(LinearLayout)findViewBiId(R.id.view)代码>您没有将视图
变量分配给任何对象,这可能会导致代码中出现NullPointerException
尝试在XML文件中的线性布局下添加此行:
android:id=“@+id/view”
并将此行添加到您的onCreate
:
view=(LinearLayout)findViewBiId(R.id.view)代码>您需要为您的线性布局分配一个id
<LinearLayout
android:id="@+id/view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="#FFFFFF"
您需要为您的LinearLayout
<LinearLayout
android:id="@+id/view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="#FFFFFF"
试试这个代码
这对我有用。。。
在youyr xml文件中,将线性布局的id设置为视图
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:id="@+id/view"
android:background="#FFFFFF"
>
这对我有用
快乐编码..试试这段代码
这对我有用。。。
在youyr xml文件中,将线性布局的id设置为视图
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:id="@+id/view"
android:background="#FFFFFF"
>
这对我有用
快乐编码..单击后使用以下代码:
view.setBackgroundColor(Color.DKGRAY);
例如:
public void onClick(View v) {
view.setBackgroundColor(Color.DKGRAY); //Add any color you want
}
单击一次后,使用以下代码:
view.setBackgroundColor(Color.DKGRAY);
例如:
public void onClick(View v) {
view.setBackgroundColor(Color.DKGRAY); //Add any color you want
}
我照你说的做了,它只改变了按钮的线条,而不是大厅背景。我是不是在分配按钮时做错了什么?我的意思是包装内容或其他什么尝试将此线性布局的高度更改为匹配\u家长
我照你说的做了,它只改变了按钮的线条,而不是大厅背景。我做了什么分配按钮有问题,我是说包装内容或其他东西尝试将此LinearLayout
的高度更改为match\u parent
我按你说的做了,它只更改了按钮的行,而不是大厅背景。你需要将android:id=@+id/view
添加到基本布局中,这意味着它覆盖了所有的背景我照你说的做了,它只改变了按钮的线条而不是大厅的背景。你需要在基本布局中添加android:id=@+id/view
,这意味着它覆盖了所有的背景