I've a customised status bar with gradient effect. I've achieved it using this solution. The main factor was WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
flag. Have a look on the code...
public class ForgotPasswordActivity extends AppCompatActivity implements Runnable {
private AppBarLayout appBarLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forgot_password);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) toolbar.getLayoutParams();
params.height += getStatusBarHeight();
toolbar.setLayoutParams(params);
toolbar.setPadding(0, getStatusBarHeight(), 0, 0);
setSupportActionBar(toolbar);
// Default settings of the action bar
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
//actionBar.setHomeAsUpIndicator(R.mipmap.ic_arrow_back_white_24dp);
//actionBar.setHomeButtonEnabled(true);
//actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(0);
}
// Adding offset listener to block app bar sliding on touch
appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
appBarLayout.post(this);
}
public int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
@Override
public void run() {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
if (behavior != null) {
behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
@Override
public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
return false;
}
});
}
}
}
Now the problem is, soft input keyboard is covering the EditText as following...
Even I've also tried following links but nothing's happening...
I've to do it anyhow, because entire theme depends on this approach. So is there any way to adjust layout according to keyboard or achieve gradient in status bar without FLAG_LAYOUT_NO_LIMITS?