Problem with Image Button visibility! Android

眉间皱痕 提交于 2019-12-02 12:29:11

问题


I have an Image button. I made it invisible. But the onClick event is not getting triggered which makes the button visible. The button should initially be visible for 5seconds, become invisible and then visible again if I click there.

private ImageButton nextbutton;
    @Override
    protected void onCreate( Bundle savedInstanceState )
    {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.first );
        nextbutton = ((ImageButton)findViewById( R.id.NextButton ));
        nextbutton.setVisibility(View.INVISIBLE);
        nextbutton.setOnClickListener( new OnClickListener()
        {
            @Override
            public void onClick( View v )
            {
                nextbutton.setVisibility(View.VISIBLE);
                startActivity( new Intent( FirstActivity.this, SecondActivity.class ) );
            }
        });
    }

回答1:


You are trying to click an invisible button? Try using a visible button with a blank drawable, ie no background or src attributes.

when you click it, dynamically change the source attributes by inserting your desired drawable.

this will definitely make it clickable.




回答2:


When you have made the ImageButton Invisible then how will you click an invisible ImageButton.



来源:https://stackoverflow.com/questions/6959754/problem-with-image-button-visibility-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!