all, I tired to make a action bar overlay the layout of my activity. I am also use support library to support android 2.1 and above, the layout of my activity is as follows:
<!-- activity_display_message.xml in layout folder -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="?attr/actionBarSize"
tools:context=".DisplayMessageActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
The manifest.xml is like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher">
android:theme="#style/CustomActionBarTheme" >
<!-- some code for main activity -->
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
The styles.xml which defines CustomActionBarTheme is as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<!-- Support library compatibility -->
<!-- Setting values in the default namespace affects API levels 7-13 -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
<item name="windowActionBarOverlay">true</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#color/orange</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText"
parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
</resources>
Now the problem when applied CustomActionBarTheme is that the text (passed from main activity) which supposed to be displayed in the TextView of display_message_activity disappeared, so I am guessing if it is due to the overlay action bar that covers the text message, and so anyone has any idea how to solve the issue?
cheers
I think that's the cause that doesn't show your text and to solve your problem you should set margin top for TextView with the value: ?attr/actionBarSize
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize" />
I hope you have solved your problem and this is a correct answer :)
Related
I have the following simple layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</android.support.constraint.ConstraintLayout>
How can I keep the notification permanently displayed in my app? My SDK-Version is 27. I already tried a lot of the solutions available and none seemed to have worked.
<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">
My styles.xml:
<resources>
<!-- Base application theme. -->
<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:statusBarColor">#color/colorPrimaryDark</item>
<item name="android:windowLightStatusBar">true</item>
</style>
</resources>
Looks like SceneForm's BaseARFragment makes the host Activity use immersive mode via an OnWindowFocusChangeListener. I think you should be able to add your own OnWindowFocusChangeListener and it would be called after the other one, so you could override this behavior.
arFragment.arSceneView?.viewTreeObserver.addOnWindowFocusChangeListener { hasFocus ->
if (hasFocus) {
window.decorView
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
}
}
Read up on the system UI flags to decide which ones you actually want.
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>
The used theme for the actionbar is Theme.AppCompat.Light when using Theme.Holo the issue does not exists.
I am using a custom view for the support v7 actionbar:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" >
</LinearLayout>
And I get the following result :
How do I remove the black line/divider between the layout and the actionbar.
I have tried changing the actionbar style but with not much of a success.
<resources>
<style name="Theme.Styled" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="dividerVertical">#null</item>
<item name="android:background">#null</item>
<item name="android:paddingTop">0dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:showDividers">none</item>
<item name="android:background">#null</item>
<item name="android:divider">#null</item>
<item name="android:dividerHeight">0dp</item>
<item name="android:dividerPadding">0dp</item>
</style>
</resources>
Here is my Activity Source:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.actionbar);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
}
}
This is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbartest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Styled" >
<activity
android:name="com.example.actionbartest.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>
You're probably looking for the android:windowContentOverlay attribute.
To remove that drop shadow, simply set the value to #null in your theme, like so:
<style name="Theme.Styled" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:windowContentOverlay">#null</item>
</style>
How do I remove the black line/divider between the layout and the actionbar.
I think you are mistaken. There really isn't a divider present. To confirm:
Open the layout file you're using with setContentView(R.layout.activity_main). Whatever the base container is, set its background to the color you use with the ActionBar. For example, let's say that the base container is a LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" > <<<====== Add this
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
You'll see that the ActionBar now blends with the activity's view.
What you are currently seeing is a gradient defined as:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#ffe8e8e8"
android:endColor="#ffffffff"
android:angle="270" />
</shape>
Here's where the background comes from:
(taken from platforms/android-17/data/res/values/themes.xml)
<style name="Theme.Light">
<item name="windowBackground">#android:drawable/screen_background_selector_light</item>
....
To get rid of it, you can either give your base container a background color, or override this attribute's value in your project's res/values/themes.xml:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">#android:color/white</item>
</style>
Edit:
This is the project setup:
res/layout/activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
tools:context=".MainActivityCompat" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
res/values/styles.xml
<resources>
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
AndroidManifest.xml:
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.trialcompat.MainActivityCompat"
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>
MainActivityCompat.java:
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
public class MainActivityCompat extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.actionbar);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
}
}
R.layout.actionbar is the same as the one you have posted in the question. And this is the result:
As you can see, I cannot reproduce the divider issue. Am I missing something here?
Beside #Vikram answer, add this to the theme:
<item name="android:windowContentOverlay">#android:color/white</item>
Recommendation: Use the same color you use on your layouts. For the default one, use #null
Hope this helps.
I had the same issue. After lots of trials and fails I found that the bug was because of the 9patch background of the action bar.
I switched the 9patch with a regular image and the black line was gone.
For api version >= 21
AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout);
appBarLayout.setOutlineProvider(null);
I want to set up for my all my activity's background white.
Still didnt find the way how to do is simple and that it will change my text color to black.
I am using sherloack bar on some my activity's and I think that's my problem.
My manifest looks like that:
<application
android:icon="#drawable/rss"
android:label="#string/app_name"
android:theme="#style/CustomTheme"
>
<activity
android:name=".ListRss"
android:label="#string/title_activity_listr_rss"
android:theme="#style/Theme.Sherlock" >
</activity>
<activity android:name="RssItem" >
</activity>
<activity android:name="editRss.AddNewRss">
</activity>
<activity android:name="openRssItem.WebActivity" >
where my style
<style name="CustomWindowTitleBackground">
<item name="android:background">#FFFFFF</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:background">#FFFFFF</item>
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
and my activity for example
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/BackgroundColor"
android:id="#+id/myScreen">
<LinearLayout
android:id="#+id/linearLa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/image"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="centerCrop"
android:src="#drawable/rss" />
will glade to receive a simple solution that solve the background color to white and the text for black.
You can't use android:Theme as the parent theme of your theme, if you want to use ActionBarSherlock(unless you want to override everything...).
If you want to have the light theme you have to use this:
<style name="CustomTheme" parent="Theme.Sherlock.Light">
[...]
</style>
I'm trying to implement the ViewPagerIndicator with SherlockActionBar. It works: I can slide the fragments, but the style doesn't work!
It looks like this:
related topic: https://github.com/JakeWharton/Android-ViewPagerIndicator/issues/66
I know what's going wrong:
In the sample of VPI, the style of a page is set in AndroidManifest.xml by (for example)
<activity
android:name=".SampleTabsDefault"
android:theme="#style/Theme.PageIndicatorDefaults">
</activity>
But when I add that android:theme element to my own Manifest.xml I get the following exception:
03-16 11:06:24.400: E/AndroidRuntime(483): Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
I've also tried to copy all the style-information to styles.xml, but that also doesn't work.
Can you tell me how to set a style to the VPI?
Thank you!
EDIT:
Now I've added
<activity
android:name=".SampleTabsDefault"
android:theme="#style/StyledIndicators">
</activity>
to my Manifest.xml
and the following style in styles.xml
<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="StyledIndicators" parent="Theme.BataApp">
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
Result: I don't get any Exception, see the style, but I now I can't see any fragments :(
The code of the activity can be found here: http://pastebin.com/hsNgxFDZ
Screenshot of current page with style:
In order to see the Fragments, you'll have to somehow extend an Android base-theme. In order to see the ViewPagerIndicator, you'll have to somehow include those style-definitions. The answer is to create your own theme that extends the ActionBarSherlock-theme (which extends the Android base-themes), and implements the ViewPagerIndicator-styles.
Example:
<style name="myTheme" parent="#style/Theme.Sherlock">
<!-- If you want to use the default ViewPagerIndicator-styles, use the following: -->
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
<!-- If you want to implement your custom style of CirclePageIndicator, do it like so: -->
<item name="vpiCirclePageIndicatorStyle">#style/myCirclePageIndicator</item>
<!-- Put whatever other styles you want to define in your custom theme -->
</style>
<style name="myCirclePageIndicator" parent="Widget.CirclePageIndicator">
<item name="fillColor">#color/my_custom_circle_indicator_fill_color</item>
</style>
Then in your Manifest, set android:theme="#style/myTheme" to the <application> or to your <activity>s.
Note that you don't have to include all 4 "vpi..."-styles; you only have to include those that you use. E.g. if you're only using the CirclePageIndicator, you only have to include <item name="vpiCirclePageIndicatorStyle">...</item> and can leave out the other 3 item declarations.
I accidentally removed android:layout_weight="1" when adding styles.
So for other who want to implement VPI with ABS:
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.viewpagerindicator.TabPageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
style="#style/StyledIndicators" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
styles.xml:
<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
etc.
</style>
<style name="StyledIndicators" parent="Theme.BataApp">
<item name="vpiTitlePageIndicatorStyle">#style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">#style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">#style/Widget.TabPageIndicator.Text</item>
</style>
Thank you #Reinier! :D