In my application I have something like this:
Button playBtn = (Button) findViewById(R.id.play);
ProgressBar pb1 = new ProgressBar(this);
playBtn.setBackgroundDrawable(pb1);
But this is not working. And I know why, - pb1 is not a drawable. But how otherwise I can set the background of my play button to the progress bar? I use开发者_如何学运维 a programmatic way of creating a progress bar and I have a play button in my .xml resource.
Ah, you really can't do what you're trying to do: there is no way to use one View as the background of another View.
What you can do is something similar to what the Android battery meter in the notification area does: make a number of drawables (I think the battery meter uses 5 or 6 different images, 1 for each stage of the recharge process) and then use a timer or external events to switch the background drawable for your button: this simulates a progress meter.
Let me know if that helps.
Make transparent button (background="@null") and place it on the ProgressBar using RelativeLayout or FrameLayout.
This is simpler than it seems:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@null"
android:textColor="@android:color/white"
android:text="asdasd"/>
</FrameLayout>
Make the same in code if you want.
Are you sure you need the Button
here? Mb it's enough to place the ProgressBar
only and make it clickable by setting onClickListener
.
精彩评论