I am very new to android develop & Android Studio. I was trying to create a simple app with a text input field so that that user can input text. (Again very new to this and just messing around with android development/studio).
Anyway, when I've added the 'TextInputLayout' and then a input text field from the palette, I get the above error.
I have tried to refresh as hinted to me. Also tried uninstalling Android Studio, different APKs. I have tried some solutions from another post on stack-overflow by looking through the manifest file and the style.xml files and haven't had any luck.
Was wondering if anyone could help me resolve this issue again I am extremely new to android development and Programming in general, so it may be an easy fix but I've ran out of ideas LOL.
Below is the code I currently have my 'activity_main.xml' file.
<?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.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="#string/input_text"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
This is an android studio bug with dependencies of support library. I also faced same problem few days ago.
Go to build.gradle file (inside app folder).
Then change the version of dependencies of support library -- replace 28.0.1-alpha3 to 28.0.1-alpha1
Then go to styles.xml file (at app/res/values folder) and add this item in your style named AppTheme.
<item name="textInputStyle">#style/Widget.Design.TextInputLayout</item>
First if you create themes in res file so, locate it in manifest file with android:theme="#style/Theme.xyz" and in the layout design you have to check the same theme is applied there or not.
In addition to above users answer, if you are unsure about how to determine which certain version of the support library you should upgrade or downgrade, let Android Studio choose that best applies to you. Simply target it by putting .+ symbol right after the main version of the library, which works pretty well for me.
Go to Gradle Scripts, open build.gradle(Module:app), replace the version of support library dependencies as following:
dependencies {
implementation 'com.android.support:appcompat-v7:28.+'
}
and then go to styles.xml file located at app/res/values folder and add this item
<item name="textInputStyle">#style/Widget.Design.TextInputLayout</item>in your style named AppTheme. .
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="textInputStyle">#style/Widget.Design.TextInputLayout</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Hope it helps to others, too. Let me know
Related
I'm making my first app in android studio. It's going well so far, but I've come across this stumbling block:
I have absolutely no idea how to edit already defined colours.
Here's some screenshots from two of the activities:
Inside the layout .xml code i have coloured everything like this:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/layoutReset"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/resetNutsButton"
android:layout_width="300dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_margin="30dp"
android:background="#drawable/round_corners"
android:backgroundTint="#color/Accent1" //Accent colour
android:fontFamily="#font/lemonmilkregular"
android:text="Reset nuts"
android:textAlignment="center"
android:textColor="#color/Back1" //grey
android:textSize="25sp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Everything in the project has been coloured using the colors.xml file and, as you can see from the 2nd picture, I would like to add the option to choose an accent colour to be used everywhere that is currently red.
I've looked through many questions and I can see that editing any of the resource files during runtime is not possible, so I was wondering what the best way is to go about this.
As I said, this is my first app, so I may just be missing something simple.
Any input is appreciated, and if you need any more details please tell me.
It's true, you're not able to edit colours or themes at runtime.
You could potentially try something like (in styles.xml):
<!-- Colors -->
<style name="Indigo">
<item name="colorPrimary">#color/indigoColorPrimary</item>
<item name="colorPrimaryDark">#color/indigoColorPrimaryDark</item>
<item name="colorAccent">#color/indigoColorAccent</item>
</style>
<style name="Blue">
<item name="colorPrimary">#color/blueColorPrimary</item>
<item name="colorPrimaryDark">#color/blueColorPrimaryDark</item>
<item name="colorAccent">#color/blueColorAccent</item>
</style>
<style name="Red">
<item name="colorPrimary">#color/redColorPrimary</item>
<item name="colorPrimaryDark">#color/redColorPrimaryDark</item>
<item name="colorAccent">#color/redColorAccent</item>
</style>
And then in your code:
getTheme().applyStyle(R.style.Blue, true);
Also remove any places in your layouts where you're explicitly setting the colours, you just want it to use the theme's colours:
android:backgroundTint="#color/Accent1"
Themes are immutable, so you can't.
There's a style called Widget.Material.Button that has an animation effect that I really like (it makes a "splash" around your click), and I want to be able to reuse it in my code.
I'm trying to make it have a transparent background color, since it is gray by default which does not look good when applied to my ViewGroup objects.
Is there an easy way to keep the animation, but get rid of the background color?
I already tried setting the property android:background="#android:color/transparent", but that causes the animation to completely stop working.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="#android:style/Widget.Material.Button"
tools:targetApi="lollipop">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, world!"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is just another line of text."/>
</LinearLayout>
As mentioned in this blog under 'Clickable Views', you can use android:background="?attr/selectableItemBackground:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?attr/selectableItemBackground">
...
</LinearLayout>
Sorry for giving the wrong bit initially. The problem as looking a bit deeper is the background color is defined already as part of whatever you are using for your MaterialTheme extension for color highlights. Ironically, they have sources from transparent elsewhere but not here ?
What you want to so is make TWO new xml files to define your properties
In vales-v21/styles.xml you can redefine these any way you like or eliminate values you don't want to override
IF YOU JUST WANT THE RIPPLE, USE THE DRAWABLE CODE DEFINED AT THE BOTTOM
<style name="MyMaterialButton" parent=android:Widget.Material.Button>
<item name="background">#drawable/material_background_ripple</item>
<item name="textAppearance">?attr/textAppearanceButton</item>
<item name="minHeight">48dip</item>
<item name="minWidth">88dip</item>
<item name="stateListAnimator">#anim/button_state_list_anim_material</item>
<item name="focusable">true</item>
<item name="clickable">true</item>
<item name="gravity">center_vertical|center_horizontal</item>
</style>
Then your button background style
/drawable-v21/material_background_ripple.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#android:color/PICK_RIPPLE_COLOR_HERE">
<item android:drawable="#drawable/btn_default_mtrl_shape" />
</ripple>
Redacted:
Have you tried
customView.getWindow().setBackgroundDrawableResource(R.color.transparent);
?
I'm using this https://github.com/makovkastar/FloatingActionButton library for FloatingActionButtons in my project.
On some smaller devices, for example the Acer Liquid Z4 (Android version 4.2.2, screen 480x800) or the Genymotion Galaxy S2 image (Android version 4.1.1, screen 480x800) the FABs have a black box around them:
I tried to narrow this down, removed any special stuff from my theme making it look like this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
and also put the buttons in the most simple layout:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="de.immowelt.android.immobiliensuche.ui.FabTestActivity">
<com.melnykov.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
but the box remains. On the other hand I tried to recreate the effect with a new project but couldn't do it.
The box disappears when using the mini size version or disabling the shadow.
Any ideas on what my problem is?
PS: I tried cleaning the project ;)
I was using that library but then decided to make my own, set this as the background to an imageButton or something. I used a textview because all I needed was a +. It looks pretty good in my app.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Drop Shadow Stack -->
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<padding android:right="1dp" android:bottom="1dp" />
<solid android:color="#00262626" />
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<padding android:right="1dp" android:bottom="1dp" />
<solid android:color="#0D262626" />
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<padding android:right="1dp" android:bottom="1dp" />
<solid android:color="#26262626" />
</shape>
</item>
<!-- Background -->
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<solid android:color="#448AFF"/>
</shape>
</item>
</layer-list>
The problem was that the FloatingActionButton class makes use of a drawable called shadow.9.png for the shadow. I also had a shadow.9.png in my drawables and the library class obviously picked up the wrong one (mine).
Renaming my drawable solved the problem.
I know it is a known issue, but my ide(android studio) is saying that setContentView can't be resolved. In fact, it was working perfect well but I tried to import some android plugin but then I deleted all the plugin files I added. Then I noticed that setContentView wasn't recognized anymore.
I tried everything I found on SO (cleaning, rebuilding....). I read it is mainly related to the xml view files, but I have no error in these files. How can I do ?
Update :
when running gradle build, I get some success build. Then when I want to run the project, I get in my console
org.gradle.execution.TaskSelectionException: Task 'compileDebug' is ambiguous in root project 'NewsFeeder'. Candidates are: 'compileDebugAidl', 'compileDebugJava', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugTestAidl', 'compileDebugTestJava', 'compileDebugTestNdk', 'compileDebugTestRenderscript
Edit 2 : here's my layout
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="400px"
android:layout_height="800px">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:background="#color/white"
android:headerDividersEnabled="false"
/>
<ListView
android:id="#+id/right_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:background="#color/white"
android:headerDividersEnabled="false"
/>
</android.support.v4.widget.DrawerLayout>
Edit 3: I restart the ide, and now I get in the activity_main file
Failed to find style 'listViewStyle' in current theme (8 similar errors not shown) "?android:attr/listPreferredItemHeight" in attribute "minHeight" is not a valid format. (Edit) (3 similar errors not shown)
Try this,
Make sure that setContentView is in the onCreate Method, and that all the other required pieces of code are in the method. Here is a basic template to help you out
package com.example.app
import android.app.Activity;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
As mentioned you have deleted all plugins make sure some required plugins are still there in place.
You can check them from Settings > Plugins
It seems android plugins default tasks are missing so make sure you have
apply plugin: 'android'
in your module's build.gradle file.
EDIT(As per the discussion in comments) :
It seems you are using actionbarsherlock in your project make sure you have applied Sherlock theme in your AndroidManifest.xml file
Something Like this :
If you are using style.xml for you theming
In your style.xml
<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<style name="AppTheme" parent="AppBaseTheme">
//other style elements here or leave it blank
</style>
in your AndroidManifest.xml file
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</application>
when i customize title bar in view by adding a image, i face an issue as the images is not fixed to the edges accurately. I have attached the image where you can see space between the window margin and image added. How to overcome this problem. Below are the code that i have used to customize the title bar. Can anyone help me to fix this issue.
java code :
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.home_view);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.upwindow);
layout code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="32dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/up_bar"
android:src="#drawable/up_bar" />
<TextView
android:id="#+id/pagename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Sify MyStorage"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
create style xml in values folder :
<resources>
<style name="CustomWindowTitleBackground" />
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">32dp</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground
</item>
</style>
</resources>
then refer it in manifest as :
android:theme="#style/CustomTheme">
this will solve it .
hope this help .
Do you have different images for different resolutions? It might be that your image simply does not fit that space, and that you need a larger one. Be careful though, you might run into issues with your app working across different platforms with scaling.
You need to play a little with styling in order to override this behavior. Define a custom theme (style) as below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTitle">
<item name="android:background">#drawable/up_bar</item>
</style>
<style name="myTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/customTitle</item>
</style>
</resources>
and then use this theme in your activity by applying android:theme="#style/myTheme" to your desired activity tag in AndroidManifest.xml
requestWindowFeature(Window.FEATURE_NO_TITLE);
and setBackground to your layout in layout file...
Like,,,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:background="#drawable/up_bar" <---Add this
android:layout_height="32dp">
and Remove imageview from xml