在单击按钮时,应在按钮的最左角上显示复选标记图标,在同一按钮上嵌入时,复选标记图标应放置。在这种情况下,有些人可以帮助我吗?

有帮助吗?

解决方案

您可以在按钮的左侧添加可见性的imageView(允许说Tick.png)。并设定其异象。这是代码:

<LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ImageView
            android:id="@+id/iv_tick"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:src="@drawable/tick"/>
        <Button 
            android:id="@+id/btn_tick"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Press"/>
    </LinearLayout>
.

现在,按钮单击事件您设置的Visibilty:

Button btn_tick = (Button)findViewById(R.id.btn_tick);
    btn_tick.setOnClickListener(new OnClickListener()
        {
            public void onClick(View v)
            {
                ImageView iv_tick = (ImageView)findViewById(R.id.iv_tick);
                int visibility = iv_tick.getVisibility();
                if(visibility == View.VISIBLE)
                {
                    iv_tick.setVisibility(View.GONE);
                }
                else
                {
                    iv_tick.setVisibility(View.VISIBLE);
                }
            }
        });
.

其他提示

虽然已经回答,这是一个替代解决方案:添加Unicode Checkmark符号。其中两个中有:\ u2713和\ u2714。只需将它们添加到字符串中:

<string name="button_label_on">\u2713 on</string>
<string name="button_label_off">off</string>
.

当然,您也可以将此直接放入布局代码中:

<Button
   ...
   android:text="\u2713 on"
   />
.

checkout the

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top