【问题标题】:Android. How do I dynamically change the color of the entire FrameLayout instead of just the color of the View backround?安卓。如何动态更改整个 FrameLayout 的颜色,而不仅仅是 View 背景的颜色?
【发布时间】:2011-01-12 20:38:04
【问题描述】:

这是我的 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);

在 FrameLayout 中是否可以同时更改视图背景和整个屏幕的颜色?

感谢您的宝贵时间。

【问题讨论】:

    标签: android view background android-framelayout


    【解决方案1】:

    您可以使用findViewById 获取FrameLayout 并在其上设置背景颜色。

    【讨论】:

    • 感谢您的快速回复。在我为我的框架布局分配了一个 ID 后,您的建议非常有效。再次感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    • 1970-01-01
    • 2013-12-15
    • 2014-04-05
    • 1970-01-01
    • 2011-05-21
    相关资源
    最近更新 更多