Issue
I have this item in my top_navigation_menu layout I would like to enable it in my OnCreate method programmatically:
<item
android:id="@+id/action_button"
android:enabled="false"
android:visible="false"
android:clickable = "false" />
Exemple : When User Open New Activity Enable this Item.
Edit : this is a follow up from my previous question so I'm trying another approach.
Edit : after some research I found
Button btn = (Button) findViewById(R.id.action_button);
btn.setEnabled(true);
btn.setClickable(true);
Not sure which one I should use
Solution
I'm confused about what you want to achieve. Visible, clickable and enable are same components attr state with different output
visibleis your button visibility if you set it value tofalseit gonna be gone and clear theRectfrom the screen alsoenableit's mean prevents the user from tapping theButton. The appearance of enabled and non-enabledButtonmay differ, if thedrawablesreferencedclickableit's mean how yourButtonreacts to click events. false mean disable the click events
What can I see is you tried to put them all, which is bad for me. One state is enough depending on what you trying to achieve for. This is examples and my suggestions :
Enable State, XML :
<Button android:id="@+id/action_button" android:enabled="false"/>Visibility State, XML :
<Button android:id="@+id/action_button" android:visible="false"/>Clickable State, XML :
<Button android:id="@+id/action_button" android:clickable="false"/>
And then from your OnCreate you can change change their state as follow
Button myButton = findViewById(R.id.action_button);
//for visibility state
myButton.setVisibility(View.VISIBLE);
//for enable state
myButton.setEnable(true);
//for clickable state
myButton.setClickable(true);
Answered By - hnspaces
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.