1

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...

Screenshots

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?

User
  • 4,023
  • 4
  • 37
  • 63
  • For future references, this answer (https://stackoverflow.com/a/33370845) applies for `FLAG_LAYOUT_NO_LIMITS` as well. – Mihail Slavchev Oct 12 '17 at 15:15
  • Hello, did you figure it out? – Sourabh Nov 19 '17 at 06:05
  • Hello, did you figure it out? – Denny Jan 06 '18 at 16:39
  • Yeah I did it.. Do you want to see? – User Jan 06 '18 at 16:40
  • Hi Sourabh S Nath & Denny, I've fixed it using https://stackoverflow.com/questions/43140039/how-to-set-status-bar-background-as-gradient-color-or-a-drawable-in-android/43405486#43405486 approach, But there's a person @Bhargav Rao , who deleted my answer. – User Jan 06 '18 at 16:43
  • For future readers, the deleted answer mentioned by Khan pointed to this answer to a related question: https://stackoverflow.com/questions/43140039/how-to-set-status-bar-background-as-gradient-color-or-a-drawable-in-android/43405486#43405486 – stkent Mar 25 '21 at 19:26

0 Answers0