Android Lollipop theme compatibility All API Version [ 7- 21] - java

Hi I'm using Lollipop theme for all other API version, but i don't use Lollipop toolbar and style actions. I have created a ActionBar like custom ActionBar layout like left and right corner Buttons and title is in center.
Here the my the theme but it doesnot work. can you update this issue. also tell me the style for "Theme.AppCompat.Light"
// Style code
res/values/theme.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
</resources>
values-v21/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">#android:transition/move</item>
<item name="android:windowSharedElementExitTransition">#android:transition/move</item>
</style>
</resources>
// Activity code like.
public class CreateAccountActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// To set the custom title with Button
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.create_account_screen_1);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.title_layout_with_two_button);
((TextView) findViewById(R.id.myTitle)).setText(R.string.create_acc);
// ((Button) findViewById(R.id.back_button)).setText(R.string.login);
((Button) findViewById(R.id.right_button))
.setVisibility(View.INVISIBLE);
}

Related

App styling in Android Studio

I cannot seem to find the right solution to increase and decrease the text size of the whole android app project.I want to give user an option so the user can change the font size of the whole app. I tried extend my Base-activity to Text-view but didn't do the trick i hope anyone here can help me.
You'll have to update textSize of TextViews from Design tab in
.xml files that you can find at res > layout like activity_main.xml file.
If you want to change size for whole app, Try custom themes and set it dynamically.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:textSize">16sp</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme2" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:textSize">15sp</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme3" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:textSize">17sp</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Create separate themes for different sizes, and use this class for setting it.
public class themeUtils
{
public static int cTheme;
public static void changeToTheme(Activity activity, int theme)
{
cTheme = theme;
activity.finish();
activity.startActivity(new Intent(activity, activity.getClass()).addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION));
}
public static void onActivityCreateSetTheme(Activity activity)
{
try
{
activity.setTheme(cTheme);
}
catch (Exception e)
{
activity.setTheme(R.style.AppTheme); //default
}
}
}
In your activity, call this method before super.oncreate() method,
#Override
protected void onCreate(Bundle savedInstanceState) {
themeUtils.onActivityCreateSetTheme(this);
super.onCreate(savedInstanceState);
...}
Finally change theme in your code where ever you want,
themeUtils.changeToTheme(this, themeselected);//your theme name

How do I change the color of the timepicker in my Android app?

As you can see from the image below, I'm using the time picker in my app.
I need to change the color but don't know how...
Thanks for the help.
This can be easily achieved from xml (5.0+ only)
v21/themes.xml
<style name="Theme"
parent="MyTheme.Base">
<item name="android:dialogTheme">#style/Theme.Dialog</item> <!-- TimePicker dialog -->
<item name="android:alertDialogTheme">#style/Theme.Dialog</item> <!-- Alert dialog -->
</style>
<style name="Theme.Dialog"
parent="android:Theme.Material.Light.Dialog">
<item name="android:colorAccent">#color/...</item>
<item name="android:colorPrimary">#color/...</item>
<item name="android:colorPrimaryDark">#color/...</item>
</style>
Edit
Please note that as of Android Support Library 22.1.0 there is a new AppCompatDialog available! http://android-developers.blogspot.de/2015/04/android-support-library-221.html
Try this code
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TimePicker" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowIsFloating">true</item>
<item name="colorAccent">#color/primary</item>
<item name="colorControlActivated">#color/secondary</item>
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary</item>
<item name="android:buttonBarNegativeButtonStyle">#style/DatePickerTheme.ButtonBarButtonStyle</item>
<item name="android:buttonBarPositiveButtonStyle">#style/DatePickerTheme.ButtonBarButtonStyle</item>
</style>
<style name="DatePickerTheme.ButtonBarButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#color/primary</item>
</style>
</resources>
The first one is colorAccent, the second is colorControlActivated and the last one does not belong to the timepicker, it belongs to dialog so you should apply the an style similar to this post

Remove ActionBar Border

So, here is the problem.
This border is showing up and I would like to remove it or at least change opacity. There was a shadow drop before because of Lollipop version, but I removed that with actionBar.setElevation(0);
Here is actionbar code from my class:
final android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setElevation(0);
actionBar.setCustomView(R.layout.appbar_layout);
Here is my style code:
<resources>
<style name="Theme.Example" parent="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBar.Solid.Example</item>
<item name="android:toolbarStyle">#style/ToolbarStyle</item>
<item name="toolbarStyle">#style/ToolbarStyle</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:actionModeBackground">#android:color/white</item>
</style>
<style name="ToolbarStyle" parent="#style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">0dp</item>
<item name="android:contentInsetStart">0dp</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="ActionBar.Solid.Example" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">#android:color/white</item>
<item name="android:titleTextStyle">#style/ActionBarStyle.Transparent.TitleTextStyle</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="ActionBarStyle.Transparent.TitleTextStyle" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#drawable/appbar_logo</item>
</style>
In your app styles set the following:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light">
<item name="colorPrimary">BORDER COLOR HERE</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
</style>
And in your manifest:
<application
android:label="#string/app_name"
android:theme="#style/MyTheme">
...
</application>
More likely, if your api version >= 21, you need this:
AppBarLayout appBarLayout = findViewById(R.id.player_app_bar_layout);
appBarLayout.setOutlineProvider(null);

Set a custom for actiobar using Android Studios

I've tride to set another color for my actiobar quite a while now.
I've search on google and tried multiple solutions. but non of them have worked out for me.
The code i got now is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#cac09f</item>
</style>
</resources>
This causes my app to crash and displays this:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I then tried to set the theme to "Theme.Appcompat" but this wont change the color of the actionbar.
Does anyone know a solution for this?
I run this on a phone running android 4.4.4.
My project is for API 16 and higher (4.1)
You're using an activity from the support package (AppCompatActivity), it can only use compatibility themes (Theme.AppCompat).
The reason why setting a custom action bar background didn't work, is because you also need to use compatibility attributes:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/my_red</item>
<item name="background">#color/my_red</item>
</style>
<color name="my_red">#cac09f</color>
guy I think that would be better you to use a toobar, because it is easier of work.
use this code in your xml:
<android.support.v7.widget.Toolbar
android:id="#+id/tbMain"
android:layout_width="match_parent"
app:theme="#style/style_toobar"
android:layout_height="?attr/actionBarSize"
/>
in the style.xml use this:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
</style>
<style name="style_toobar" parent="Theme.AppCompat">
<item name="popupTheme">#style/Theme.AppCompat.Light</item>
<item name="colorControlNormal">#color/colorAccent</item>
</style>
in the activity use:
Toobar tbMain = (Toobar)findViewById(R.id.tbMain);
setSupportActionBar(tbMain);

How to change Up button Android ActionBar?

I searched many solutions and implemented solution of Jake Wharton
My style.xml code is
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/aeromyorders</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/bg_actionbar</item>
<item name="android:homeAsUpIndicator">#drawable/up_caret</item>
</style>
</resources>
but still my Actionbar up button is default what i have to do now? i also replaced Vaues-v11 style also.. My Min SDK is 15 Max 19 in Manifest
Try this code in Your Activity. set Your Custom Back Button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_actionbar_screen_back);
Hope it helps...

Categories