See Android background image
I wanted to know how I can set up a background image, so that it looks on absolutely the entire screen, pull out the ActionBar and I want to put the notification bar transparent so that the image looks there too. Thanks in advance.
Had tried:
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background"/>
2 answers
Several options, the first would be by defining an image as a background using the property android:background
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mi_fondo">
</RelativeLayout>
The second, using a ImageView
with properties, android:layout_width="match_parent"
and android:layout_height="match_parent"
, defining an image with the property android:background
:
<ImageView
android:id="@+id/myImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mi_fondo"/>
The third using an ImageView, using the property android:scaleType="fitXY"
:
<ImageView
android:id="@+id/Load_img_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:scaleType="fitXY"
android:src="@drawable/mi_imagen" />
And the fourth, defining a theme, where you define the image :
<style name="miFondo" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowBackground">@drawable/mi_fondo</item>
<item name="android:windowNoTitle">true</item>
</style>
And load it from your activity, defining the topic in the AndroidManifest.xml
<activity android:name=".MainActivity"
android:theme="@style/miFondo"></activity>
For the background image, give a background to the Layout with android:background="@drawable/background_game_screen"
, example:
<LinearLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:background="@drawable/background_game_screen"
For notification bar transparency try placing this in your theme:
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
And if you want to remove the ActionBar do it with this:
android:theme="@android:style/Theme.NoTitleBar"
Or by Code:
ActionBar actionBar = getActionBar(); //o en su caso getSupportActionBar();
actionBar.hide();