@Override public void findViewsWithText(ArrayList<View> out, CharSequence toFind, int flags) { toolbar.findViewsWithText(out, toFind, flags); }
public static View getToolbarLogoIcon(Toolbar toolbar){ //check if contentDescription previously was set boolean hadContentDescription = android.text.TextUtils.isEmpty(toolbar.getLogoDescription()); String contentDescription = String.valueOf(!hadContentDescription ? toolbar.getLogoDescription() : "logoContentDescription"); toolbar.setLogoDescription(contentDescription); ArrayList<View> potentialViews = new ArrayList<View>(); //find the view based on it's content description, set programatically or with android:contentDescription toolbar.findViewsWithText(potentialViews,contentDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); //Nav icon is always instantiated at this point because calling setLogoDescription ensures its existence View logoIcon = null; if(potentialViews.size() > 0){ logoIcon = potentialViews.get(0); } //Clear content description if not previously present if(hadContentDescription) toolbar.setLogoDescription(null); return logoIcon; }
public static View getToolbarNavigationIcon(Toolbar toolbar){ //check if contentDescription previously was set boolean hadContentDescription = TextUtils.isEmpty(toolbar.getNavigationContentDescription()); String contentDescription = !hadContentDescription ? toolbar.getNavigationContentDescription() : "navigationIcon"; toolbar.setNavigationContentDescription(contentDescription); ArrayList<View> potentialViews = new ArrayList<View>(); //find the view based on it's content description, set programatically or with android:contentDescription toolbar.findViewsWithText(potentialViews,contentDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); //Nav icon is always instantiated at this point because calling setNavigationContentDescription ensures its existence View navIcon = null; if(potentialViews.size() > 0){ navIcon = potentialViews.get(0); //navigation icon is ImageButton } //Clear content description if not previously present if(hadContentDescription) toolbar.setNavigationContentDescription(null); return navIcon; }
@Override public void findViewsWithText(ArrayList<View> out, CharSequence toFind, int flags) { toolbar.findViewsWithText(out, toFind, flags); }
final Toolbar toolbar = ...; toolbar.setNavigationContentDescription("up"); setActionBar(toolbar); final ArrayList<View> outViews = Lists.newArrayList(); toolbar.findViewsWithText(outViews, "up", View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); outViews.get(0).setRotation(180f);
static void centerToolbarTitle(@NonNull final Toolbar toolbar) { final CharSequence title = toolbar.getTitle(); final ArrayList<View> outViews = new ArrayList<>(1); toolbar.findViewsWithText(outViews, title, View.FIND_VIEWS_WITH_TEXT); if (!outViews.isEmpty()) { final TextView titleView = (TextView) outViews.get(0); titleView.setGravity(Gravity.CENTER); final Toolbar.LayoutParams layoutParams = (Toolbar.LayoutParams) titleView.getLayoutParams(); layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; toolbar.requestLayout(); //also you can use titleView for changing font: titleView.setTypeface(Typeface); } }
public static View getNavigationIcon(Toolbar toolbar){ //check if contentDescription previously was set boolean hadContentDescription = TextUtils.isEmpty(toolbar.getNavigationContentDescription()); String contentDescription = !hadContentDescription ? toolbar.getNavigationContentDescription() : "navigationIcon"; toolbar.setNavigationContentDescription(contentDescription); ArrayList<View> potentialViews = new ArrayList<View>(); //find the view based on it's content description, set programatically or with android:contentDescription toolbar.findViewsWithText(potentialViews,contentDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); //Nav icon is always instantiated at this point because calling setNavigationContentDescription ensures its existence View navIcon = null; if(potentialViews.size() > 0){ navIcon = potentialViews.get(0); //navigation icon is ImageButton } //Clear content description if not previously present if(hadContentDescription) toolbar.setNavigationContentDescription(null); return navIcon; }
public static View getToolbarNavigationIcon(Toolbar toolbar){ //check if contentDescription previously was set boolean hadContentDescription = TextUtils.isEmpty(toolbar.getNavigationContentDescription()); String contentDescription = !hadContentDescription ? toolbar.getNavigationContentDescription() : "navigationIcon"; toolbar.setNavigationContentDescription(contentDescription); ArrayList<View> potentialViews = new ArrayList<View>(); //find the view based on it's content description, set programatically or with android:contentDescription toolbar.findViewsWithText(potentialViews,contentDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); //Nav icon is always instantiated at this point because calling setNavigationContentDescription ensures its existence View navIcon = null; if(potentialViews.size() > 0){ navIcon = potentialViews.get(0); //navigation icon is ImageButton } //Clear content description if not previously present if(hadContentDescription) toolbar.setNavigationContentDescription(null); return navIcon; }
toolbar.findViewsWithText(potentialViews,contentDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);