Android Showcase View how to use? - java

Well For Showcase View
I using this:
https://github.com/amlcurran/ShowcaseView
After importing files it gives error. this is my errors and improted .jar files
Errors says
in java
R cannot be resolved to a variable
in style
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light'.
again, in style
error: Error: No resource found that matches the given name: attr 'android:fontFamily'.
Also Are there any tutorial to use Showcase view in my project. I can not find and I didnt understant from github project. it is not clear.

This library works Awesome for all. How it works?? i want to highlight a toolbar option. Now just add the library and write code like this.
you can use multiple showCaseView using this code
1 add Library in our Gradle.build
implementation 'com.github.mreram:ShowCaseView:1.0.5'
simple call this method with pass title, Description Text, view or view Id and Type
ShowIntro("SetTheme", "Select Theme and Apply on your video", R.id.button_tool_theme, 1);
method create like this
private void ShowIntro(String title, String text, int viewId, final int type) {
new GuideView.Builder(this)
.setTitle(title)
.setContentText(text)
.setTargetView((LinearLayout)findViewById(viewId))
.setContentTextSize(12)//optional
.setTitleTextSize(14)//optional
.setDismissType(GuideView.DismissType.targetView) //optional - default dismissible by TargetView
.setGuideListener(new GuideView.GuideListener() {
#Override
public void onDismiss(View view) {
if (type == 1) {
ShowIntro("Editor", "Edit any photo from selected photos than Apply on your video", R.id.button_tool_editor, 6);
} else if (type == 6) {
ShowIntro("Duration", "Set duration between photos", R.id.button_tool_duration, 2);
} else if (type == 2) {
ShowIntro("Filter", "Add filter to video ", R.id.button_tool_effect, 4);
} else if (type == 4) {
ShowIntro("Add Song", "Add your selected song on your video ", R.id.button_tool_music, 3);
} else if (type == 3) {
ShowIntro("Overlay", "Add your selected overlay effect on your video ", R.id.button_tool_overlay, 5);
} else if (type == 5) {
SharePrefUtils.putBoolean("showcase", false);
}
}
})
.build()
.show();
}

Here for this I am using this library
https://github.com/amlcurran/ShowcaseView
This library works really great. How it works??
Suppose i want to highlight a menu option. Now just add the library and white this code.
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.menu_main);
setSupportActionBar(toolbar);
ViewTarget target = new ViewTarget(toolbar.findViewById(R.id.menu_id_launcher));
new ShowcaseView.Builder(this)
.setContentTitle("Its My Navigation Drawer")
.setContentText("Click here and you will get options to navigate to other sections.")
.useDecorViewAsParent() //this is the difference
.setTarget(target)
.build();
}
and finally you have to make your menu show always like this
<item
android:id="#+id/menu_id_launcher"
android:orderInCategory="100"
android:icon="#mipmap/ic_launcher"
android:title="#string/action_settings"
app:showAsAction="always" />
Now just run the app i think this will works perfectly.

I usually use another library for showcase views. It creates bubbles instead of concentric circles but it works really well. Maybe it is also useful for your requirements and with this one you don't have importing problems.
You just have to add 'implementation 'com.elconfidencial.bubbleshowcase:bubbleshowcase:1.3.0' in your build.gradle file of your app and synchronize your project.
It works similar to ShowCaseView library:
BubbleShowCaseBuilder(this) //Activity instance
.title("foo") //Any title for the bubble view
.targetView(view) //View to point out
.show() //Display the ShowCase
Source https://github.com/ECLaboratorio/BubbleShowCase-Android

The sample you use needs the ActionBarSherlock Library, you can read it in the instructions from the github page: "To use the sample download ActionBarSherlock and add it as a dependency to the library project. Use point 1 on the "Including in your project" instructions at the link."
download ActionBarSherlock and import it (only the library, you don't need the samples)
right click to your SampleActivity project and choose Properties
choose Android, click Add and include the ActionBarSherlock project
Then the style errors will go away and R can be built.

import, add actionbarsherlock library
android:fontFamily minSDK is 16, or delete this
project -> clean all

Related

How do I resolve a Redeclaration Error in Android Studio

This code is for a button that would be on the android emulator. However, when I place this code in the main activity.kt it gives me multiple errors. The first error I experience is a redeclaration error on line 9 on the main activity
package com.example.android.justjava
import android.R
import android.os.Bundle
import android.support.v7.app.ActionBarActivity
import android.view.View
import android.widget.TextView
// This activity displays an order form to order coffee.
class MainActivity : ActionBarActivity() {
protected fun onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
// this method is called when the order button is clicked.
fun submitOrder(view: View) {
display(1)
}
// This method displays the given quantity value on the screen.
private fun display(number: Int) {
val quantityTextView = findViewById(R.id.quantity_text_view as TextView
quantityTextView.text = "" + number
}
}
This activity displays an order form to order coffee.
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// This method is called when the order button is clicked.
public void submitOrder(View view) {
display(1);
}
// This method displays the given quantity value on the screen.
private void display(int number) {
TextView quantityTextView =(TextView) findViewById (R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
File tab -> Invalidate Caches/Restart (then choose invalidate and restart from the dialog that will appear)
Build tab -> Clean Project
Build tab -> Rebuild Project
This solution is just the same as #Ehsan_Haghdoust solution but letting Android Studio do that for me instead of doing that my self.
The question is for 6 months ago, but I write my answer for others face this problem in the future. I have had challenge with this error, I checked every possible way suggested by others and I FINALLY had to delete build folders in
projectFolder/
and
projectFolder/app/
manually and rebuild the project again.
The problem you face is that you have 2 activities with the same name MainActivity - one in Java, and second in Koltin. Both classes (activities in this case) are compiled into the same application - you have 2 symbols with the same name.
yes, Koltin and Java look the same after the compiler finish with them :)
In my case, I was running the app in debug mode and a direction class was generated for debug. Then I tried generating a signed APK in release mode. Then a similar class was generated in same package for release mode which caused the issue. I manually deleted just the debug folder in the Java folder(root) and the build was successful.
Build -> Select Build Variant. It was in debug, I just changed it to release mode and done.

Why I can't add an ImageView in the tabbed page?

so I just recently started to develop Android applications via Xamarin and I am struggling a LOT.
I created my application like this(in Visual Studio 2017 Community edition):
New Project -> Visual C# -> Android -> Android App(Xamarin) -> Tabbed App(Android version 5.0).
Then I drag ImageView anywhere on the screen.I try to run it and it crashes with the exception:
Unhandled Exception:
Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.BottomNavigationView
What I tried:
1) doing this in new Visual studio version - 2019.
2) Putting this in a blank app - it does work, but I need the tabbed page functionality for my app, so that's not an option.
Any tips & tricks are appreciated.Here are the images to visualize it.
Code line where it crashes
This is how it looks from the designer perspective.
Error from designer window
MainActivity.cs:
using Android.App;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;
namespace App10
{
[Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity, BottomNavigationView.IOnNavigationItemSelectedListener
{
TextView textMessage;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Error on this line.
SetContentView(Resource.Layout.activity_main);
textMessage = FindViewById<TextView>(Resource.Id.message);
BottomNavigationView navigation = FindViewById<BottomNavigationView>(Resource.Id.navigation);
navigation.SetOnNavigationItemSelectedListener(this);
}
public bool OnNavigationItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case Resource.Id.navigation_home:
textMessage.SetText(Resource.String.title_home);
return true;
case Resource.Id.navigation_dashboard:
textMessage.SetText(Resource.String.title_dashboard);
return true;
case Resource.Id.navigation_notifications:
textMessage.SetText(Resource.String.title_notifications);
return true;
}
return false;
}
}
}
Then I drag ImageView anywhere on the screen.I try to run it and it crashes with the exception:
After testing , I found that this is not your problem, this should be a bug for VS.
Solution:
After modify axml file, you need to clean project, then rebuild it. This error will not happen.
Clean Solution -> Build Solution can solve it.

How do I change the main xml file from another activity?

I am very new to Java. I am doing a school project at the moment and I have my main activity, then I have a settings activity. I am trying to modify the xml from the main activity with the settings activity. I am able to modify the settings xml file with the settings.java, but I would like to modify the main activity xml with settings.java
public class Settings extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
// Get the Intent that started this activity and extract the string
Switch switchButton;
final RelativeLayout mRelativeLayout = (RelativeLayout) findViewById(R.id.activity_settings);
final RelativeLayout mRelativeLayoutMain = (RelativeLayout) findViewById(R.id.activity_main);
switchButton = (Switch) findViewById(R.id.switch1);
switchButton.setChecked(true);
switchButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean bChecked) {
if (bChecked) {
mRelativeLayoutMain.setBackgroundColor(Color.GRAY);
mRelativeLayout.setBackgroundColor(Color.GRAY);
} else {
mRelativeLayoutMain.setBackgroundColor(Color.WHITE);
mRelativeLayout.setBackgroundColor(Color.WHITE);
}
}
});
if (switchButton.isChecked()) {
mRelativeLayoutMain.setBackgroundColor(Color.GRAY);
mRelativeLayout.setBackgroundColor(Color.GRAY);
} else {
mRelativeLayoutMain.setBackgroundColor(Color.WHITE);
mRelativeLayout.setBackgroundColor(Color.WHITE);
}}
public void toast1(View view) {
android.widget.Toast.makeText(this, "Created by Cody Walls and Tommy Serfas", android.widget.Toast.LENGTH_LONG).show();
}
/*public void switch1(View view) {
ScrollView mScrollView = (ScrollView) findViewById(R.id.scrollView);
mScrollView.setBackgroundColor(Color.GRAY);
}*/
}
In the Code I am trying to change the background of the main activity xml with :
mRelativeLayoutMain.setBackgroundColor(Color.GRAY);
and when I run the app and click the intent it will crash with the error:
"java.lang.NullPointerException: Attempt to invoke virtual method
'void android.widget.RelativeLayout.setBackgroundColor(int)' on a null
object reference"
I think the easiest way is to create an PreferenceManager.SharedPreferences, in which I recommend you to store current app data. This will help you not to loose any changes in app after you exit the it. Here is short instructions:
Create button in settings activity which will change something in main activity.
Create onClickListener for your button.
Use .SharedPreferences to store was you button clicked or not. (I recommend storing boolean variables, this way you can store was button clicked or not.)
I both of your activities in onCreate method call .getSharedPreferences to read saved app values. (I mean to read was the button clicked or not.)
Use app values you got from 4. to change any element in activity. (For example if you stored that button was clicked, then change some TextView text or etc.)
I hope you understood the idea.
Link to the Android developer tutorial about App key values storing & saving
Link to the StackOverflow much easier explanation & examples
There are a couple of ways of doing this (Some of which depends on how you are switching back and forth from each activity). It also depends on what things you are changing.
From your settings page, as you are changing different settings, you'll save this content within Preferences. (You can see more how to use Preferences here: https://examples.javacodegeeks.com/android/core/ui/settings/android-settings-example/ or by just Googling it).
On you main activity, depending on how you come back to it (onStart most likely), you can setup the things you need to programmatically.
So, you may need to do a little research on the Android lifecycle and how each cycle works (https://developer.android.com/guide/components/activities/activity-lifecycle.html), how to program the UI programmatically through Java (http://startandroid.ru/en/lessons/220-lesson-16-creating-layout-programmatically-layoutparams.html), and the Preferences Android library to save certain settings.
The xml isn't meant to be "altered". You can change the UI programmatically. It's possible to build an Android app without any xml. When Android was first built, it didn't use the xml to create the UI. It was all done through Java. It was then added to use xml to create your activities or fragments or any UI component. This made things easier for more static activities or activities with very little dynamic content.

First addCommand() item in a Form fails when used with native theme

I have encountered a problem when using the the addCommand() method of the Form class along with the Native theme - other themes work fine. See the following example:
Form hi = new Form("Hi World");
hi.addComponent(new Label("Hi World"));
// with native theme - can't click on the first command in the list
hi.addCommand(new Command("Dummy1") {
public void actionPerformed(ActionEvent ev) {
Dialog.show("Dummy1 Clicked!", "You clicked the Dummy1", "OK", null);
}
});
hi.addCommand(new Command("Dummy2") {
public void actionPerformed(ActionEvent ev) {
Dialog.show("Dummy2 Clicked!", "You clicked the Dummy2", "OK", null);
}
});
hi.show();
When I create an application using the code above, a click on the second command ("Dummy2") produces the expected Dialog, but a click on the first command ("Dummy1") does nothing.
This only happens when using the Native theme. If I switch to Flat Blue, then clicking on either command produces the expected Dialog.
This behavior happens both on the Simulator and on a real Android device (don't know about iOS).
Fyi, my toolchain is NetBeans IDE v8.2, Java 1.8.0_25, with the CodenameOne plugin v3.6.0.
Has anyone else seen this? Am I missing something? If so, is there a workaround?
If the element is very narrow and very close to the top the click might be misinterpreted as a click out of bounds or on the status bar area. You need to set the styling of the SideCommand to have a sensible default as this element is very application specific. Otherwise touches might be lost.
I tried styling the SideCommand but it didn't seem to help. What worked for me was to define a style for TitleArea and simply uncheck Derived for the Padding settings (I left them all set to 0px).
I have no idea why this works - I would have thought that the derived values would have been zero in any case.

Android onCreateOptionsMenu is not displaying

In my android activity, i removed the Action Bar by using this Theme
<style name="Theme.NoTitle" parent="#android:style/Theme.NoTitleBar"></style>
but my problem is “onCreateOptionsMenu” is not display, I tried this method to create
that pls see
private void getOverflowMenu()
{
try
{
ViewConfiguration config = ViewConfiguration.get(Home.this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null)
{
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config , false);
}
} catch (Exception e)
{
e.printStackTrace();
}
}
in this “onCreateOptionsMenu” is not displaying. please help me
but it displaying in Samsung
Because: in Samsung mobile has its own hardware menu button, but not in nexus etc
please see the image
finally i got the answer
in my AndroidManifest.xml i just removed this line
android:targetSdkVersion="18"
If you don't have action bar and neither a menu button (on most devices) where do you want to display your menu??
The easiest way is to use PopupMenu. Add a button somewhere in your layout and on the click even add the PopupMenu (Dropdown menu). If you want to use it for devices starting Android 2.1 use a Support Library.
You have HERE the android documentation about PopupMenu.
From SDK Manager you can download and see the support library v7 sample which includes PopupMenuHelper.
Hope it helps. Good Luck!

Categories