Browse Category

UI

Navigation Component: How to move the Drawer under the ToolBar?

Navigation Drawer Activity Template

Recently I was struggling with Navigation Component and succeded in solving some of its issues. I am happy to share with you the solutions I’ve found.

GitHub Repo: https://github.com/Pulimet/NavigationComponentSample

Create a project and select the template “Navigation Drawer Activity”. You will get the ToolBar, Drawer and navigation stuff for free as shown in the screenshot.

Now, let’s assume that we got a request to move the drawer under the ToolBar. We need to modify activity_main.xml for that.

Create vertical LinearLayout and make it wrapping DrawerLayout

Open app_bar_main.xml copy AppBarLayout and paste it as a first item in the previously created LinearLayout.

Also from the app_bar_main.xml get the include (content_main) and put it as a first child of DrawerLayout instead of existing include of app_bar_main.xml.

Delete app_bar_main.xml file

In v21\styles.xml – remove the line that makes status bar transparent.

Keep Reading

Indicators library

Recently, I created a custom view, and after having used it for several of my projects, I decided to publish it as a library.

How to use it: https://github.com/Pulimet/Indicators-Library

<net.alexandroid.utils.indicators.IndicatorsView
    android:id="@+id/indicatorsView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    app:indicatorSize="20dp"
    app:paddingBetweenIndicators="16dp"

    app:selectedDrawable="@drawable/custom_selected"
    app:unSelectedDrawable="@drawable/custom_unselected"/>

Hot to get bitmap from VectorDrawable?

* Checked on API: 17, 21, 23

public static Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) {
    Drawable drawable = AppCompatDrawableManager.get()
            .getDrawable(context, drawableId);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        drawable = (DrawableCompat.wrap(drawable)).mutate();
    }

    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}

Keep Reading

SearchView – Text color and icons change

 
SearchView mSearchView = (SearchView) findViewById(R.id.searchview);

SearchView.SearchAutoComplete mSearchSrcTextView = (SearchView.SearchAutoComplete) 
        findViewById(R.id.search_src_text);
mSearchSrcTextView.setTextColor(Color.WHITE);

ImageView mClearImage = (ImageView) findViewById(R.id.search_close_btn);
mClearImage.setImageResource(R.drawable.custom_x_button);

ImageView mHintIcon = (ImageView) findViewById(R.id.search_mag_icon);
mHintIcon.setImageResource(R.drawable.customSearchButton);

Handle links in TextView by Activity

1. Link creation (don’t forget to change the package name):

        mTextView= (TextView) findViewById(R.id.init_terms_text);
        mTextView.setText(
                Html.fromHtml("By continuing you accept our " +
                        "<a href=\"net.your.packagename://terms\">terms</a> " +
                        " and " +
                        "<a href=\"net.your.packagename://privacy\">privacy policy</a> "));
        mTextView.setMovementMethod(LinkMovementMethod.getInstance());
        mTextView.setLinksClickable(true);

2. Add target Activity to AndroidManifest.xml (don’t forget to change the package name):
Keep Reading

Clickable links in TextView

An example how to set text and clickable links in TextView:

textViewLinks

TextView textView = (TextView) findViewById(R.id.init_terms_text);
textView.setText(
        Html.fromHtml("By continuing you accept our " +
                "<a href=\"http://www.terms.com\">terms</a> " +
                " and " +
                "<a href=\"http://www.privacypolicy.com\">privacy policy</a> "));
textView.setMovementMethod(LinkMovementMethod.getInstance());

Infinite ViewPager

MainActivity – onCreate()

...
SectionsPagerAdapter mSectionsPagerAdapter = 
        new SectionsPagerAdapter(getSupportFragmentManager(), numOfPages);
ViewPager viewPager = (ViewPager) findViewById(R.id.container_view_pager);
viewPager.setAdapter(mSectionsPagerAdapter);
viewPager.setCurrentItem(1000 * numOfPages);
...

Keep Reading

Stretchable bitmap image short guide – 9-patch/.9.png

  1. png9Add one pixel width transparent border to your image (png).
  2. On the top transparent line that we added, paint a black line and it would mark the stretchable zone on the x-axis.
  3. On the left transparent line that we added, paint a black line and it would mark the stretchable zone on the y-axis.
  4. On the right and bottom transparent lines that we added, paint a black lines and they would mark the content zone.
  5. Check that all the pixels that we’ve added around the image are transparent or completely black.
  6. You should add the markers after you’ve created the images for all dimensions.

Keep Reading

  • 1
  • 2