From 401dba6d83052cf0c9c60a74e8460e356f39bcb2 Mon Sep 17 00:00:00 2001 From: MChen321 <76930316+MChen321@users.noreply.github.com> Date: Thu, 8 Sep 2022 21:05:30 -0500 Subject: Added a clear search bar text button (#1063) --- .../infinityforreddit/activities/SearchActivity.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java index cf28ff85..f9fa34f3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -92,6 +92,8 @@ public class SearchActivity extends BaseActivity { Toolbar toolbar; @BindView(R.id.search_edit_text_search_activity) EditText searchEditText; + @BindView(R.id.clear_search_edit_view_search_activity) + ImageView clearSearchTextImageView; @BindView(R.id.link_handler_image_view_search_activity) ImageView linkHandlerImageView; @BindView(R.id.subreddit_name_relative_layout_search_activity) @@ -154,6 +156,8 @@ public class SearchActivity extends BaseActivity { setSupportActionBar(toolbar); + clearSearchTextImageView.setVisibility(View.GONE); + searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false); searchOnlyUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_USERS, false); @@ -236,6 +240,9 @@ public class SearchActivity extends BaseActivity { } }); + clearSearchTextImageView.setVisibility(View.VISIBLE); + } else { + clearSearchTextImageView.setVisibility(View.GONE); } } }); @@ -250,6 +257,10 @@ public class SearchActivity extends BaseActivity { return false; }); + clearSearchTextImageView.setOnClickListener(view -> { + searchEditText.getText().clear(); + }); + linkHandlerImageView.setOnClickListener(view -> { if (!searchEditText.getText().toString().equals("")) { Intent intent = new Intent(this, LinkResolverActivity.class); @@ -378,6 +389,7 @@ public class SearchActivity extends BaseActivity { int toolbarPrimaryTextAndIconColorColor = mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor(); searchEditText.setTextColor(toolbarPrimaryTextAndIconColorColor); searchEditText.setHintTextColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor()); + clearSearchTextImageView.setColorFilter(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); linkHandlerImageView.setColorFilter(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); int colorAccent = mCustomThemeWrapper.getColorAccent(); searchInTextView.setTextColor(colorAccent); -- cgit v1.2.3