Android- ActionBar hidden in emulator but showing in XML layout - android

I used getSupportActionBar().hide(); The result is as expected, action bar hidden during app testing but in XML design view its still visible and thats a problem because i need to visualise how the app looks. Any way i can make it disappear in the XML design view?

That's happening because you are programmatically disabling actionbar, and your IDE doesn't know if it happens or not.
Add this to res/values/style.xml (create one if you don't have one)
<style name="AppThemeNoTitleBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
and put this under application tag in AndroidManifest.xml
android:theme="#style/AppThemeNoTitleBar"
so from the scratch (assuming you don't have anything, it should look like this.
res/values/style.xml
<resources>
<style name="AppThemeNoTitleBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp" >
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppThemeNoTitleBar" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

I think you have theme for your activity in your manifest. if you remove your theme that contains the actionbar, problem is solved.

Related

How To Set SupportRTL in AndroidManifest for Specifed Activity

i removed Action Bar from all activities Then I put to specific activity an action bar and when i used SupportsRtl (in Specifed Activity) for change title position but title position still no changed
styles :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="myTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#FFFFFF</item>
</style>
</resources>
Manifest :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.classmanager">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FirstTab" />
<activity android:name=".SecondTab" />
<activity android:name=".ThirdTab" />
<activity android:name=".AddNewClass"
android:theme = "#style/myTheme"
android:supportsRtl="true" <==== DONT WORK
android:label="اضافه کردن کلاس">
</activity>
</application> </manifest>
You can't do such thing in Manifest.xml.
I recommend set android:layoutDirection="rtl" into your activity parent layout to set just that specific activity support rtl.
this article has great information about layout directions support.
When you enable support for RTL layouts like this:
<application
...
android:supportsRtl="true">
You enable the use of this feature for every activity in the app.
This suggests that the problem probably lies in the layout of your AppBarLayout/ Toolbar.
In order for the application to properly reflect the direction, you should use the appropriate attributes - instead of using Left/Right, you should use Start/End ones. To read more check Android Developers Blog.
You can also use the automatic Android Studio option by selecting Refactor > Add RTL Support Where Possible...

tool bar not removed?

So im trying to remove my tool bar on android design page but can't for some reason.
XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
</LinearLayout>
Did you set the theme of your Activity in your Manifest without an ActionBar?
In styles.xml:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
And in your AndroidManifest.xml:
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />
Then in your design page, you'll need to select the theme you just created in the dialog.
Add this in manifest file
<application
...
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>

How can I find default colors for a given Android Theme?

I am using the AppCompat.NoActionBar theme. I'd like to know how to find the default colors for EditText lines and the Titles in DialogFragments. These defaults look like a teal color and I am also wondering if they are the same color or different. Is there an Android resource that lists out default colors by platform version?
Here is the themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar" >
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowDisablePreview">true</item>
</style>
<style name="FloatingLabel" parent="#android:style/TextAppearance" >
<item name="android:textColor">#color/colorFlLabelActivated</item>
</style>
...
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example..." >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme" >
<activity
android:name="com.example..."
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example..."
android:windowSoftInputMode="stateVisible|adjustResize"
/>
</activity>
</application>
colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#357EC7</color>
<color name="colorHint">#C0C0C0</color>
<color name="colorFlLabelActivated">#357EC7</color>
</resources>
goto to your android sdk and follow the path
\sdk\platforms\android-22\data\res\values\colors.xml
this contains the color code for all the items of the default theme
platform android-22 folder name can be different depending upon which platform tools you have installed for your sdk
As such there is no theme wise documentation but you might find following links useful and interesting.
For Theme Styling
Look at this documentation Styling the Action Bar
For Details on Themes and its Components
Please see this R.style
For Colour Details and Designing
See This Color palette ,UI color application ,Themes or you might want to have look at this Designing in Android

custom action bar keeps disappearing when i switch between fragments using the navDrawer

I wanted to add my own custom action bar to the drawer navigation by Google which i have figured out, the problem is, that when I try to open the drawer the Action bar then disappears, along with the icon that allows me to toggle the drawer is also gone for good. it again disappears when i click on my next fragment activity. I also noticed that if i leave the theme of the app back to its default theme everything works fine.
here's my custom theme style class
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:background">#f0f0</item>
</style>
</resources>
manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.navigationdrawerexample"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#android:style/Theme.Holo.Light.DarkActionBar">
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
When it works i use #android:style/Theme.Holo.Light.DarkActionBar for the theme

Logo not showing in getSupportActionBar()

How to show logo/icon in header bar with getSupportActionBar(). I get just show text title.
In manifest i have add below:
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/icon"
android:killAfterRestore="false"
android:label="#string/app_name"
android:logo="#drawable/icon"
android:theme="#style/mainStyle" >
<activity
android:name=".MainActivity"
android:logo="#drawable/icon"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
In style.xml
<style name="mainStyle" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="background">#drawable/actionbar_background</item>
<item name="android:background">#drawable/actionbar_background</item>
<item name="displayOptions">showTitle|homeAsUp|useLogo</item>
<item name="android:displayOptions">showTitle|homeAsUp|useLogo</item>
</style>
But not showing icon/logo. just showing text app name. what is wrong with my code?
I want to get show logo/icon in beside left appname and if click it go to back or go to home, like as Google Play App.
Thanks very much.
add showHome in displayOption and android:displayOptions it will work
UPDATE :
Simply avoid use displayOption in styles and add getSupportactionBar().setDisplayHomeAsUpEnabled(true); in activity. It Will also solve your problem.

Categories

Resources