Duplicating items with android: - android

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.

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...

Android Material Design colours not applied consistently

My activity_main.xml has the theme I am looking for. Some activities such as activity_disaster.xml has a partial application, and one activity_disaster_overview.xml has nothing, and is missing the action bar.
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.sherman.magic.idlehands">
<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"
android:theme="#style/IdleHands">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DisasterActivity"
android:theme="#style/IdleHands"/>
<activity android:name=".LoggedInDisasterActivity"
android:theme="#style/IdleHands"/>
<activity android:name=".CreateDisasterActivity"
android:theme="#style/IdleHands"/>
<activity android:name=".DisasterOverviewActivity"
android:theme="#style/IdleHands"></activity>
</application>
</manifest>
styles.xml
<!-- 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>
</style>
<style name="IdleHands" parent="AppTheme" >
<item name="android:colorForeground">#color/foreground_material_light</item>
<item name="android:navigationBarColor">#color/colorPrimaryDark</item>
</style>
</resources>
Working activity_main.xml:
<?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="org.sherman.magic.idlehands.MainActivity">
</android.support.constraint.ConstraintLayout>
Not working activity_disaster_overview.xml
<?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="org.sherman.magic.idlehands.DisasterOverviewActivity">
</android.support.constraint.ConstraintLayout>
MainActivity Code:
package org.sherman.magic.idlehands
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
How can I make them consistent to match activity_main.xml. Rather than a mixed bag of results.
It turned out to be a version of Android studio. I upgraded to 3.0.1 an the issues disappeared.

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>

Android- ActionBar hidden in emulator but showing in XML layout

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.

Android overdraw background. How set correctly?

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.

Categories

Resources