How to customize ActionBar background image?
Try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/test"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
</LinearLayout>
theme
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="android:windowActionBar">false</item>
</style>
activity
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView()
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().setStatusBarColor(Color.TRANSPARENT);
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
}
RESULT
How to set background image in actionbar android
Please read this article: http://cyrilmottier.com/2013/05/24/pushing-the-actionbar-to-the-next-level/
There you will find example and tutorial about your questuion
And also you can set action bar background like this.
private void setActionBar() {
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setCustomView(R.layout.header_actionbar);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionbar_blue)));
TextView tvHeader = (TextView) findViewById(R.id.tv_title_header_actionbar);
TextView tvSubheader = (TextView) findViewById(R.id.tv_subtitle_header_actionbar);
tvSubheader.setVisibility(View.GONE);
}
call setActionBar()
in your oncreate()
.
Add Activity's background image in ActionBar
windowActionBarOverlay
should work.
If your using android support library, then you need to do like this
<item name="windowActionBarOverlay">true</item>
Here is an example custom style ...
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#40000000</item>
</style>
Custom ActionBar with a background image
You can design your own actionBar
view, you may even inflate it from any xml, and then just:
getActionBar().setCustomView(yourView);
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
To adjust the height of your bar, you could do it like this:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- 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/Widget.Holo.Light.ActionBar.Solid.Inverse">
<!-- the height you desire according to your dimen -->
<item name="android:height">@dimen/action_bar_height</item>
</style>
Then, apply your theme. It works for me
Common background image for Actionbar (Toolbar) and statusbar
to set image in action make your toolbar like this
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/float_transparent"
app:popupTheme="@style/AppTheme.PopupOverlay" >
<ImageView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:scaleType="fitXY"
android:src="@drawable/home_top_image"
/>
</android.support.v7.widget.Toolbar>
and in activity theme m change your primary color and primary dark color to transparent color
like this
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@android:color/transparent</item>
<item name="colorPrimaryDark">@android:color/transparent</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
Actionbar items are not shown when the background image is white
The page on Imagery has a section on "Text protection". Quoting from there:
To make typography legible on top of imagery, apply text protection in
the form of scrims. Scrims are lightweight, translucent material
layers.
So if you want to ensure the text is legible you add a scrim to your Toolbar
, e.g. (if it's not possible to edit the images) a View
with a background made of a shape drawable with a color gradient.
How to customize ActionBar background image?
Try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/test"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
</LinearLayout>
theme
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="android:windowActionBar">false</item>
</style>
activity
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView()
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().setStatusBarColor(Color.TRANSPARENT);
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
}
RESULT
Android ActionBar Background Image
final ActionBar actionBar = getActionBar();
BitmapDrawable background = new BitmapDrawable (BitmapFactory.decodeResource(getResources(),
R.raw.actionbar_background));
background.setTileModeX(android.graphics.Shader.TileMode.REPEAT);
actionBar.setBackgroundDrawable(background);
See this
Related Topics
Installation Failed with Message Invalid File
Android Device Chooser -- Device Not Showing Up
Filtering Accelerometer Data Noise
Setexactandallowwhileidle - Is Not Exact as of Developer Reference
Android Hello, Gallery Tutorial -- "R.Styleable Cannot Be Resolved"
Mylib.So Has Text Relocations. This Is Wasting Memory and Is a Security Risk. Please Fix
Create/Copy File in Android Q Using Mediastore
How to Include Data Files with the App's APK
How to Block Outgoing Calls and Text Sms
How to Change the Android Startactivity() Transition Animation
Difference Between Extending Lifecycleactivity,Activity,Actionbaractivity & Appcompactactivity
App Not Setup: This App Is Still in Development Mode
Android: Adding Static Header to the Top of a Listactivity
Ontouchevent Not Working on Child Views
Setrotation(90) to Take Picture in Portrait Mode Does Not Work on Samsung Devices