Why I see Do not request Window.FEATURE_SUPPORT_ACTION_BAR? - java

This is a simple app with a tag navigation. And I can't open it with getting a mistake.
A part of it is:
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:572)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:159)
at com.example.tabexperiment.MainActivity.onCreate(MainActivity.java:29)
And here is a 28-th and 29-th lines in MainActivity(the message above says mistake is in 29-th line):
androidx.appcompat.widget.Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
I tried to cope with the problem but all what I found is that I should add this code in themes file:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
and this line in Manifest:
android:theme="#style/Theme.TabExperiment"
So, I have that in my code but nothing is still working.
Help me, please.

you can use this:
<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
OR
<activity android:name=".activity.YourActivity"
android:theme="#style/AppTheme.NoActionBar"/>

Related

Removing Title Bar on Android App

So I know there are a ton of these questions, but every time I try what they say, my app does not seem to remove the title bar. I have done the style change:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowNoTitle">true</item> <!-- This should work but it does not -->
</style>
I have also tried:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide(); //This guy here
setContentView(R.layout.activity_title);
The above works but I still want to use the space the title bar takes for content in my app, which is why I want to be able to modify the XML code rather than use java. Any suggestions?
You can either:
<style name="noActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and in your layout(at the root layout)
android:theme="#theme/noActionBar"
Or
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
However, the last one also hides the Statusbar. You can also set the theme to a default theme(look through the themes and find those with NoActionBar). The last one is useful if you have no plans to style the activity(for an instance if you use SurfaceView) with custom colors, etc.
For an instance you can change AppBaseTheme to have the parent Holo.Light.NoActionBar or any similar theme, but the name has to contain NoActionBar, othervise it has an actionbar
Add the below theme to style.xml:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then set this theme to your Activity in manifest:
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />

Android Action Bar Text Custom Color

I am using a theme in styles.xml as below:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/md_blue_700</item>
<item name="android:colorAccent">#color/md_blue_900</item>
<item name="android:colorPrimaryDark">#color/md_blue_900</item>
<item name="android:windowBackground">#color/md_white_1000</item>
<item name="android:colorControlNormal">#color/md_blue_700</item>
<item name="android:colorControlActivated">#color/md_blue_700</item>
<item name="android:colorControlHighlight">#color/md_blue_700</item>
<item name="android:textColorPrimary">#color/md_white_1000</item>
</style>
which I am declaring as android:theme in AndroidManifest.xml:
<activity
android:name=".LoginActivity"
android:theme="#style/AppTheme"
android:label="#string/activity_login_actionbar" />
The problem is highlighted in red in the image below.
Since I am setting
<item name="android:textColorPrimary">#color/md_white_1000</item>
to white the text in the progress bar also appears white and is invisible. If I change it to gray, the text in the action bar also changes to gray which I do not want.
I have tried things such as creating a seperate theme for the progress dialog but when I do that I lose the rounded corners of the dialog box and such.
This is my java code for creating the spinner:
progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setTitle("Attempting Sign In");
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
How should I go about solving this problem?
All answers appreciated!
You can use Theme.AppCompat.Light.DarkActionBar and remove <item name="android:textColorPrimary">#color/md_white_1000</item> in your theme style, then the title will become white. You can check the comparison between Light and Dark themes here
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/md_blue_700</item>
<item name="android:colorAccent">#color/md_blue_900</item>
<item name="android:colorPrimaryDark">#color/md_blue_900</item>
<item name="android:windowBackground">#color/md_white_1000</item>
<item name="android:colorControlNormal">#color/md_blue_700</item>
<item name="android:colorControlActivated">#color/md_blue_700</item>
<item name="android:colorControlHighlight">#color/md_blue_700</item>
</style>

How to show ActionBar MenuItem Divider in AppCompat.ActionBar.Solid Theme

I want show divider for only beginning of menu item in particular fragment. I tried some code in my theme but its not shown.
My code here:
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="background">#color/myPrimaryColor</item>
<item name="logo">#drawable/s</item>
<item name="displayOptions">useLogo|showHome</item>
<item name="android:actionBarDivider">#color/myDrawerBackground</item>
<item name="android:showDividers">beginning</item>
<item name="titleTextStyle">#style/MyTitleTextStyle</item>
</style>
Please anyone help to fix.
Thanks in advance.

Removing default actionbar tab padding

My problem is that I can't seem to override androids default tab padding and it's making my tabs horizontally scrollable (which I don't want). I've searched around stack overflow and other sites online but i can't find a solution for my problem. I am using appcompat-v7 and I'm targeting api 21 with my minimum sdk set to api 14.
Here is my themes.xml
<style name="TSTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="colorPrimary">#color/primary_blue_500</item>
<item name="colorPrimaryDark">#color/dark_blue</item>
<item name="colorAccent">#color/primary_blue_500</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/primary_blue_500</item>
</style>
<style name="ActionBarTabStyle"
parent="#style/Widget.AppCompat.Light.ActionBar.TabView.Inverse">
<item name="android:paddingLeft">0dp</item>
<item name="android:paddingRight">0dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:paddingTop">0dp</item>
</style>
I have tried adding android: prefix but it still doesn't do anything. I have also defined my custom theme in my manifest
Any and all help is much appreciated
For this you will have to create your own style and then you can set that style to actionbar manually. This is the only way to make it done.
<item name="toolbarStyle">#style/Widget.Toolbar</item>
<style name="Widget.Toolbar" parent="#style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">0dp</item>
</style>

Change ActionBar text color

I want to change my ActionBar color to blue (#0c01e3). My code is working because the actionbar background property is doing its job. But the text won't change. Any ideas? I'm using ABS.
<style name="MyActionBar1" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:backgroundSplit">#06e301</item>
<item name="android:backgroundStacked">#06e301</item>
<item name="android:background">#06e301</item>
<item name="background">#06e301</item>
<item name="backgroundSplit">#B9001F</item>
<item name="android:textColor">#0c01e3</item>
>
Update
:
Set this in your Java Page .It works for me
ActionBar ab = getActionBar();
ab.setTitle(Html.fromHtml("<font color='#ffffff'>App Name</font>"));
On the theme, there is an attribute, actionItemTextColor, which controls this color.
Remember to specify it with and without the android: prefix when using ActionBarSherlock.
add this and then try
    <item name="android:textColor">#ffffff</item>
To improve on the answer of #IntelliJ Amiya:
getActionBar().setTitle(
Html.fromHtml("<font color='" + getResources().getColor(R.color.my_color) + "'>"
+ getString(R.string.title_home) + "</font>"));
If you want to change that using xml ...
This is what worked for me ...
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/titleBarBgColor</item>
<item name="android:titleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
<item name="android:subtitleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
<!-- Support library compatibility -->
<item name="background">#color/titleBarBgColor</item>
<item name="titleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
<item name="subtitleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="EldTheme.ActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/titleBarTextColor</item>
</style>

Categories

Resources