安卓。如何动态更改整个 FrameLayout 的颜色,而不仅仅是 View 背景的颜色?
这是我的 main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
>
<ImageButton android:background="@null" android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/sample" android:id="@+id/pressThisButton" android:layout_y="40px" android:layout_x="20px"></ImageButton>
</FrameLayout>
在 Framelayout 中,我有一个 View v,其中包含按钮 pressThisButton。
按下按钮时,我可以更改视图中按钮周围的填充背景的颜色,但不能更改整个屏幕的背景,使用
private OnClickListener buttonClickListener = new OnClickListener()
{
public void onClick( View v )
{
v.setBackgroundColor(0xffff0000);
Is there a way in a FrameLayout to change the view background and the整个屏幕的颜色?
谢谢您的宝贵时间。
This is my main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
>
<ImageButton android:background="@null" android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/sample" android:id="@+id/pressThisButton" android:layout_y="40px" android:layout_x="20px"></ImageButton>
</FrameLayout>
In the Framelayout, I have a View v which contains the button pressThisButton.
When the button is pressed I am able to change the color of the padding background surrounding the button in the view--but not the background of the entire screen--using
private OnClickListener buttonClickListener = new OnClickListener()
{
public void onClick( View v )
{
v.setBackgroundColor(0xffff0000);
Is there a way in a FrameLayout to change both the view background and the entire screen color?
Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
findViewById
获取FrameLayout
并为其设置背景颜色。You could get the
FrameLayout
usingfindViewById
and set the background color on it.