I know there are many topics with the same request but I can not fix the background problem for my application.
If I write the code like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:orientation="vertical"
android:background:"#drawable/wallpaper>
I receive the error Lint: "Possible overdraw: Root element paints the background...."
So I changed with this:
style.xml
<style name="AppTheme" parent="#android:style/Theme.Holo">
<item name="android:windowBackground">#null</item>
</style>
<style name="WallpaperTheme" parent="#style/AppTheme">
<item name="android:background">#drawable/wallpaper</item>
</style>
manifest.xml
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:allowBackup="true"
android:theme="#style/AppTheme">
<activity
android:name=".Main"
android:label="#string/title_activity_main"
android:theme="#style/WallpaperTheme">
...
...
</activity>
In this way no longer receiving the error Lint but the layout of the application is wrong, for example:
Also the buttons do not follow the correct layout ...
How do I do then?
I'm stupid!
I changed the code in this way, and the error of Lint no longer appears:
style.xml:
<style name="AppTheme" parent="#android:style/Theme.Holo">
<item name="android:windowBackground">#null</item>
</style>
manifest.xml
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:allowBackup="true"
android:theme="#style/AppTheme">
<activity
android:name=".Main"
android:label="#string/title_activity_main">
...
...
</activity>
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical"
android:background="#drawable/wallpaper">
Do you really need to change the app theme ? It seems to me that you just wanna change the background of the activity and put the layout background as the activity background... Why do you
change app theme ?
change windowBackground and not only the background ?
Here, you basically change the container/parent of the layout itself by setting it to a null decorview. You don't need this and that is what affects the placement of the linear layout.
Related
How to make RecyclerView item background transparent I need to show background image?
I tried 3 solutions given in Stack Overflow and not worked for me
1 : android:background="?android:attr/selectableItemBackground"<br>
2 : android:background="#android:color/transparent"<br>
3 : alpfha 0.4
udated i also tried
4: android:background="#null" (Answer from this post) and not working
full xml code
Try to give this on your item CardView
app:cardBackgroundColor="#android:color/transparent"
Try this:
1) In your manifest make that activity theme to Transparent-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidhub4you.transparent.background"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.androidhub4you.transparent.background.MainActivity"
android:theme="#android:style/Theme.transparent"
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>
2) Now your page will be 100% transparent, so if you need some background color then set opacity like-
<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="#80000000"
tools:context=".MainActivity" >
it helps you.
So for the layout you are inflating for the item you can use
android:background="#null"
You can also use developer options on your device to see layout bounds or check the view hierarchy to see which item is giving you problems
First add this style in styles.xml
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="colorPrimaryDark">#android:color/transparent</item>
</style>
then add this line in AndroidManifest.xml below the corresponding activity
android:theme="#style/Theme.Transparent"/>
hope it helps.
set all layout backgrouncolor= '#00000000' also to your Recycleview background color to achieve this view
set transparent color in your view
#80000000
Trying to setup my app to use Material design:
<style name="AppTheme" parent="android:Theme.Material.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:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:colorAccent">#color/colorAccent</item>
If items with android: are removed - the colors are not getting applied.
If items without android: are removed - app crashes:
Unable to start activity ComponentInfo{com.foo.bar/com.foo.bar.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.design.widget.TabLayout
Questions:
Why do I have to duplicate those?
Should I duplicate all styles like that?
EDIT:
The Manifest file is:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.foo.bar">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
EDIT2
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="#+id/tl_periods"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMinWidth="100dp"
app:tabMode="scrollable"/>
The theme of your application is not a descendant of AppCompat theme, whereas your TabLayout is from support packages.
You either have to stick with AppCompat theme and views, or entirely be support packages independent, otherwise such nasty issues will rise.
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>
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.
Hi i have to developed one sample app.Here i wish to select the app name is Admin Login and gravity is center.here i have to run the app means the app name is diplayed successfully.but the gravity is not worked for me.here i wish to align the app name is center.how can i do.please give me solutions.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidlogin.ws"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".AndroidLoginExampleActivity"
android:label="Admin Login" android:theme="#style/CustomTheme" android:gravity="center">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Edit:
<style name="CustomWindowTitleBackground">
<item name="android:background">#093f7c</item>
<item name="android:gravity">center</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
I have checked your styles. There you specify
<item name="android:gravity">center</item>
for CustomWindowTitleBackground. Its not possible because setting gravity center means it will align in center to its parent. so there is no possibility of giving the layout width to fill_parent.
so i think you must use custom xml file and align your title
Define a custom title style/theme.
Als o check com.example.android.apis.app.CustomTitle.
Try to set gravity in AndroidLoginExampleActivity.xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity ="center" >
or if you want to use gravity in sub layout then use layout_gravity in sub layout.