force layout to refresh/repaint android?
Maybe you need:
linear.invalidate();
linear.requestLayout();
after making the layout changes.
EDIT:
Run the code on a different thread:
new Thread() {
@Override
public void run() {
<your code here>
}
}.start();
And whenever you need to update the UI from that thread use:
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
<code to change UI>
}
});
How to force a view to redraw immediately before the next line of code is executed
Okay, I finally found a solution to this issue, and it's simple. It seems that the problem was just that I was executing the drawable changes in an OnClickLIstener, when I should have been doing it in an OnTouchListener. If I set an OnTouchListener for my button that looks for ACTION_DOWN and then runs setBackgroundColor on its parent layout, the change occurs immediately.
An alternative, less robust solution comes from this post. You can assign a selector for the parent layout background in xml, then in the OnTouchListener mentioned above, run setPressed(true) on that layout. It's not a great solution because the selector gives you a lot less freedom than directly changing the view's properties in code. You couldn't set the layout background to a different color by pressing a different button, for example.
Thanks to those who helped out with suggestions on this!
Android Studio Refresh Layout without Rebuilding Project
According to: Android Studio: How to 'Refresh' after adding file?
There is no refresh option for do that on AndroidStudio
There is only an option for Make project
in Build -> Build Project
.
But, i think this option will do the refresh option:
File->Synchronize
. Or equivalently, Ctrl+Alt+Y or the little circle with arrows menu button.
Update: In the new Android Studio, This feature is available. Thanks to jason.
How to refresh a view in Android
This is not the right way but I think it should do the job for simple cases:-
Restart your activity without animation.
finish();
startActivity(new Intent(this, MyActivity.class));
overridePendingTransition(0, 0);
Related Topics
How to Use Getsharedpreferences in Android
Version Conflict Updating to 8.4.0
Differencebetween Activity and Context
How to Change Textcolor in Alertdialog
Android Background Image Memory Usage
Actionbar Logo Centered and Action Items on Sides
Cardview Layout_Width="Match_Parent" Does Not Match Parent Recyclerview Width
Android - Extracting Cookies After Login in Webview
How to Display Image in Android's Textview
How to Move the Layout Up When the Soft Keyboard Is Shown Android
How to Take Camera Capture Without a Preview from a Service or Thread
Android: Using Simplecursoradapter to Get Data from Database to Listview
Gradle Error: Minimum Supported Gradle Version Is 3.3. Current Version Is 3.2
Android How to Turn on Do Not Disturb (Dnd) Programmatically
Android: Radiogroup - How to Configure the Event Listener
Android: Under What Circumstances Would a Dialog Appearing Cause Onpause() to Be Called