开发者

Show notification on screen like Toast but clickable. In short a "ClickableToast"

I have a requirement where I need to show a bar at the bottom of the screen on particu开发者_StackOverflow中文版lar event in the background thread. Also it has to be clickable.

I could consider showing a toast but toasts are not clickable. How can this be done?

Im developing on 2.1


May be it is useful for you. in layout file write this

<LinearLayout   
xmlns:android="http://schemas.android.com/apk/res/android" 
                    android:layout_width="fill_parent" 
                    android:layout_height="fill_parent"
                    android:orientation="vertical"
                    android:gravity="bottom"
                    android:paddingLeft="5px"
                    android:paddingTop="5px"
                    android:paddingRight="5px">

        <packagename.TransparentPanel
                android:id="@+id/transparent_panel" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:paddingTop="5px"
                android:paddingLeft="5px"
                android:paddingBottom="5px"
                android:paddingRight="5px">

            <Button android:id="@+id/button_click_me"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:text="Click Me!"/>

        </packagename.TransparentPanel>

and create TransparentPanel in your package

public class TransparentPanel extends LinearLayout 
{ 
private Paint   innerPaint, borderPaint ;

public TransparentPanel(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public TransparentPanel(Context context) {
    super(context);
    init();
}

private void init() {
    innerPaint = new Paint();
    innerPaint.setARGB(225, 75, 75, 75); 
    innerPaint.setAntiAlias(true);

    borderPaint = new Paint();
    borderPaint.setARGB(255, 255, 255, 255);
    borderPaint.setAntiAlias(true);
    borderPaint.setStyle(Style.STROKE);
    borderPaint.setStrokeWidth(2);
}

public void setInnerPaint(Paint innerPaint) {
    this.innerPaint = innerPaint;
}

public void setBorderPaint(Paint borderPaint) {
    this.borderPaint = borderPaint;
}

@Override
protected void dispatchDraw(Canvas canvas) {

    RectF drawRect = new RectF();
    drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());

    canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
    canvas.drawRoundRect(drawRect, 5, 5, borderPaint);

    super.dispatchDraw(canvas);
}
}

set this where you need.


You can display a dialog and change de android:background to android:background="@android:drawable/toast_frame"

If you want the same style you can use a layout With the toast's background and then apply it a animation that make the layout grow from button.


I will show a PopupWindow for a notification on top of the current activity. Found it through Google. Thanks to all for your replies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜