Remove shadow below actionbar FragmentActivity - java

Still can't remove the shadow below the actionbar.
I am using SlidingTabLayout, SlidingTabStrip, and FragmentActivity.
I already tried this:
actionBar.setBackgroundDrawable();
and in SlidingTabLayout:
tabTitleView.setTextColor();
tabTitleView.setBackgroundColor();
However, when setting the background color in tabTitleView the shadow is gone but I don't see the indicator color anymore.

I found solution on the reddit, you should to set windowContentOverlay to #null by defauld in your style.xml
Or try this method from Android SDK to your action bar

Related

Disable Material Checkbox ripple effect temporarily

I have an SpannableString text with links on com.google.android.material.checkbox.MaterialCheckBox view.
I need to disable actual checkbox toggling while user clicks on link in CheckBox text.
I achieved that by caling view.cancelPendingInputEvents() in ClickableSpan's onClick.
However, the ripple effect on the checkbox is still present. I was able to disable it by calling this, also in ClickableSpan's onClick:
var drawable = textView.background
if (drawable is RippleDrawable) {
drawable = drawable.findDrawableByLayerId(0)
textView.background = drawable
}
The problem is, how I should revert this? How to revert default MaterialCheckBox ripple effect after click is done?

How to change virtual keys color [duplicate]

In guidelines of Android 5.0, the navigation bar seems customizable:
http://www.google.com/design/spec/layout/structure.html#structure-system-bars
How can I change the navigation bar color?
I would like to use a white style.
Screenshots:
Edit: In my resources, I tested the style:
<item name="android:navigationBarColor" tools:targetApi="21">#android:color/white</item>
But the buttons are white. I would like the same renderer as the second image.
Starting from API 27, it is now possible to use the light style of the navigation bar:
<item name="android:navigationBarColor">#android:color/white</item>
<item name="android:windowLightNavigationBar">true</item>
From the documentation:
windowLightNavigationBar
If set, the navigation bar will be drawn such that it is compatible with a light navigation bar background.
For this to take effect, the window must be drawing the system bar
backgrounds with windowDrawsSystemBarBackgrounds and the navigation
bar must not have been requested to be translucent with
windowTranslucentNavigation. Corresponds to setting
SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR on the decor view.
Use this in your Activity.
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(getResources().getColor(R.color.green));
}
add this line in your v-21/style
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/black</item>
</style>
This code changes the navigation bar color according to your screen background color:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.any_color));
}
You can also use the light style for the navigation bar:
<item name="android:navigationBarColor">#android:color/white</item>
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(getResources().getColor(R.color.colorWhite));
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); //For setting material color into black of the navigation bar
}
Use this one if your app's API level is greater than 23
getWindow().setNavigationBarColor(ContextCompat.getColor(MainActivity.this, R.color.colorWhite));
getWindow().getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
May this code will not work for API level 30. Because " SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR" is deprecated in API level 30.
Check this out: https://developer.android.com/reference/android/view/View#SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
the navigation bar is not supposed to be colored
When you customize the navigation and status bars, either make them both transparent or modify only the status bar. The navigation bar should remain black in all other cases.
(source https://developer.android.com/training/material/theme.html )
BUT, you can use this library to achieve what you want :) https://github.com/jgilfelt/SystemBarTint
You can also set light system navigation bar in API 26 programmatically:
View.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
Where View coluld be findViewById(android.R.id.content).
However remember that:
For this to take effect, the window must request FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS but not FLAG_TRANSLUCENT_NAVIGATION.
See documentation.
getWindow().setNavigationBarColor(ContextCompat.getColor(MainActivity.this,R.color.colorPrimary)); //setting bar color
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); //additional setting items to be black if using white ui
Old question. But at this time we have a direct solution. May be helpful for someone.
public static void setNavigationBarColor(Activity activity, int color, int divColor) {
Window window= activity.getWindow();
window.setNavigationBarColor(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
window.setNavigationBarDividerColor(divColor);
}
}
View Official Documentation

Create a Custom Toolbar programmatically on Android

I have an app with some behavior. As an upgrade I'm going to add a Toolbar to the app. I know, I can do it putting de XML on each activity. But I want to create a Layout XML for the action Bar and inflate on each activity on the OnCreate method.
This way I think I can add the bar whenever I need it without touching the XML,and maybe make the code more efficient:
Assumptions:
I have a XML with a layout with tag "< Toolbar >"
The app has the noActionBar theme
This is an extract of OnCreate()
android.support.v7.widget.Toolbar barra =(android.support.v7.widget.Toolbar) getLayoutInflater().inflate(R.layout.barra_herramientas,null);
LinearLayout layout_actividad = (LinearLayout) findViewById(R.id.contenedor_principal);
layout_actividad.addView(barra);

Overflow dots not changing colour

The overflow dots with my activity remain white hence don't change colour when using the code below. Does anyone know how to solve this issue?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wc_bank);
ActionBar actionBar = getSupportActionBar();
getSupportActionBar().setElevation(0);
//change background colour of action bar
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#66CCCC")));
//change text colour of action bar
actionBar.setTitle(Html.fromHtml("<font color='#000099'>Hello World</font>"));
//change colour of action bar back arrow
final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(getResources().getColor(R.color.blue), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
//enable and show action bar back arrow
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(false);
final Drawable overflowDots = getResources().getDrawable(R.drawable.abc_ic_menu_moreoverflow_mtrl_alpha);
overflowDots.setColorFilter(getResources().getColor(R.color.piccadilly), PorterDuff.Mode.SRC_ATOP);
}
The problem is that you aren't doing anything with your tinted Drawable. You get an instance of your abc_ic_menu_moreoverflow_mtrl_alpha icon and you set a ColorFilter on it, but then you aren't actually using that Drawable anywhere.
Unfortunately there also isn't a good way to set a Drawable object as your overflow menu icon. If you insist on doing this in your Java code, you can use this answer to accomplish that, but it is pretty hacky.
The preferred way is to use a custom style and the android:actionOverflowButtonStyle theme attribute to reference a Drawable resource. This means that if you use this option, you need to create a new asset with the correct color and include that in your drawable resource folders. Your theme will end up looking something like this:
<style name="Your.Theme" parent="#android:style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionOverflowButtonStyle">#style/Your.Theme.OverflowStyle</item>
</style>
<style name="Your.Theme.OverflowStyle" parent="#android:style/Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">#drawable/your_overflow_icon</item>
</style>

different color on Action Bar MenuItem in different configurations programmatically

I want to set different colors to text of MenuItem that are in action bar and in different configurations - landscape and portrait.
I figured one way to that was have different colors set in Color and Color-land.I've made a custom theme in styles as follows
<style name="MyAppTheme" parent="#android:style/Theme.DeviceDefault.Light">
<item name="android:actionMenuTextAppearance">#style/MyActionBar.MenuTextStyle</item>
</style>
<style name="MyActionBar.MenuTextStyle"
parent="android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Menu">
<item name="android:textColor" >#color/button_color</item>
</style>
and then set the color black in color resource and white in color-land resource.
This would work as the activity will be created when the configuration changes.
However in my activity when the activity is created first an AlertDialog appears which leads to a REST api call and a ProgressDialog follows while the data is fetched from the server.
The problem lies in here when i would change the configuration the activity will be recreated and i will get the AlertDialog again.
if i set in the manifest <activity android:configChanges="orientation" /> the color of the menu item won't change because the activity is never created again but it will avoid the AlertDialog and would maintain the activity state.
I am looking for a way to change the MenuItem Text color in the onConfigurationChanged event. is there some way to do it?

Categories

Resources