像 Toast 一样在屏幕上显示通知,但可点击。简而言之,“ClickableToast”

发布于 2024-12-02 08:15:36 字数 115 浏览 1 评论 0原文

我有一个要求,需要在后台线程中的特定事件上在屏幕底部显示一个栏。它还必须是可点击的。

我可以考虑显示吐司,但吐司不可点击。这怎么能做到呢?
我正在2.1上开发

I have a requirement where I need to show a bar at the bottom of the screen on particular 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把昨日还给我 2024-12-09 08:15:36

也许它对你有用。
在布局文件中写入此内容

<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>

并在包中创建透明面板,

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);
}
}

将其设置在您需要的位置。

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.

人间☆小暴躁 2024-12-09 08:15:36

您可以显示一个对话框并将 android:background 更改为 android:background="@android:drawable/toast_frame"

如果您想要相同的样式,您可以使用带有 toast 背景的布局,然后应用它使布局从按钮增长的动画。

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.

甜点 2024-12-09 08:15:36

我将在当前活动顶部显示一个 PopupWindow 作为通知。通过谷歌找到了它。感谢大家的回复。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文