Android: Changing LinearLayout in a widget

后端 未结 2 1075
逝去的感伤
逝去的感伤 2021-01-16 17:12

I have this really annoying problem:

In my widget, i would like to change the background by code. I noticed on the Google doc than I can easily change the background

相关标签:
2条回答
  • 2021-01-16 17:33

    You cannot modify the background that way, due to limitations in the RemoteViews API.

    What you can do is choose a different layout -- one with the background you want -- when you create your RemoteViews instance for this particular update.

    0 讨论(0)
  • 2021-01-16 17:34

    I think the solution looks like this:

    <FrameLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    
        <ImageView android:id="@+id/label_bg" android:src="@drawable/widget_label_white"
            android:scaleType="fitXY" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:layout_gravity="center"/>
    
        <TextView android:gravity="center" android:id="@+id/label"
            android:text="Processes" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:textColor="#ffffffff"
            android:shadowColor="#ff000000" android:shadowDx="1"
            android:shadowDy="1" android:shadowRadius="1" />
    
    
    </FrameLayout>
    

    This will make the background image fit the textview nicely.

    0 讨论(0)
提交回复
热议问题