My menu is defined as:
<menu
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"
tools:context="com.opendoors.registration.BusinessProfActivity" >
<item
android:id="#+id/action_done"
android:title="#string/action_done"
android:icon="#drawable/ic_action_accept"
app:showAsAction="ifRoom"/>
</menu>
Despite using ifRoom in showAsAction, my button still goes to the overflow menu.
I have also tried replacing:
xmlns:app="http://schemas.android.com/apk/res-auto"
with
xmlns:compat="http://schemas.android.com/apk/res-auto"
as well as
app:showAsAction="ifRoom"
with
compat:showAsAction="ifRoom"
However, that doesn't work either, even though it was suggested in similar questions. What am I missing?
Maybe the following error might have something to do with this?
06-10 04:50:34.541: E/AndroidRuntime(1697): java.lang.RuntimeException: Unable to
instantiate application android.app.Application: java.lang.IllegalStateException: Unable
to get package info for com.mypackage.app; is package not installed?
Try this:android:showAsAction="ifRoom"
Have you tried to use always instead of ifRoom?
<item
android:id="#+id/action_done"
android:title="#string/action_done"
android:icon="#drawable/ic_action_accept"
app:showAsAction="always"/>
You could try: app:showAsAction="always"
Related
I want to add a check box to Navigation Drawer, and I want one of them to be default checked
I'm using this: app:actionViewClass="android.widget.Switch" as suggested in this answer.
But I couldn't figure out how to make one of them default checked. If I use this property android:checked="true", then the option is checked instead of checkbox (See image).
Does anyone know how to make it default checked (if possible, I want to do it in XML only)?
Here is my activity_drawer.xml.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="navigation_view">
<group
android:checkableBehavior="single">
<item
android:id="#+id/checkboxX-axis"
android:title="Show x-axis"
android:icon="#drawable/ic_x_axis_black_24dp"
app:actionViewClass="android.widget.CheckBox"
android:checked="true"
/>
<item
android:id="#+id/checkboxY-axis"
android:title="Show y-axis"
android:icon="#drawable/ic_y_axis_black_24dp"
app:actionViewClass="android.widget.CheckBox"
/>
<item
android:id="#+id/checkboxZ-axis"
android:title="Show z-axis"
android:icon="#drawable/ic_z_axis_black_24dp"
app:actionViewClass="android.widget.CheckBox"
/>
</group>
</menu>
You can do this:
MenuItem item = navigation.getMenu().findItem(R.id.checkboxX-axis);
CompoundButton compoundButton = (CompoundButton) item.getActionView();
compoundButton.setChecked(true);
replace navigation with the NavigationView's name.
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
Im creating menu:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.points, menu);
return true;
}
I have xml file in res/menu/points.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Item" />
</menu>
I get error - Error:(27, 36) error: cannot find symbol variable menu
why ?
Clean Rebuild helps - Thanks
I had this same problem and my issue was with the parameter Menu menu. When i first invoked Menu i didn't hit enter to set it to android.view menu, which would explain why yours is saying it doesn't understand the variable. If your not casting it as a menu type for what you're importing it as then it wont understand it as a standalone variable. I hope this helps, we could possible be working on the same tutorial. Good luck either way!!
Create a menu_main.xml file in menu folder in res folder.res>menu>menu_main.xml
<menu 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"
tools:context="com.example.myapplication.MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="action_settings"
app:showAsAction="never" />
I've run into this problem for my Android application, I'm trying to create an action bar down at the bottom of my application involving three different menus but I have aadt crashing on me. The error message I have turns up as this and aapt crashes.
<menu 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"
tools:context="com.example.authport.Auth" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_charge"
app:showAsAction="never"/>
<item
android:id="#+id/action_charge"
android:orderInCategory="1"
android:title="#string/action_settings"
app:showAsAction="always"/>
<item
android:id="#+id/action_history"
android:orderInCategory="2"
android:title="#string/action_settings"
app:showAsAction="always"/>
<item
android:id="#+id/action_setup"
android:orderInCategory="3"
android:title="#string/action_settings"
app:showAsAction="always"/>
Now is this a simple fix that I am missing or is there a larger problem that needs to be addressed? Any help would benefit me greatly.
Thank you for your posting...
It's because one of your #string is not defined
I have same return code as yours
How can i expand the actionbar like PlayNewsstand application and the image below :
What i am looking for found it here.
For your concern try using this in your manifest file ..
yourapp:showAsAction="ifRoom"
Ex:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
Complete reference :: http://developer.android.com/guide/topics/ui/actionbar.html