I am trying to create a ColorStateList programatically using this:
ColorStateList stateList = ColorStateList.valueOf(Color.RED);
to pass in setTickActiveTintList method
slider.setTickInactiveTintList(stateList);
But seems above code is not working. and I want to do it programmatically not in XML.
I am using material version : 1.0.0
Can somebody please explain me how to create this ?
Related
I'm trying to write code to automatically DM people on Instagram. Im stuck on getting the code to click on the DM button.
In UIautomatorviewer, there is no text or a resource-id, so I tried using the class.
When I run the code it doesn't click on the right thing. It clicks on the button NEXT to it.
Here is the code -
By path2 = By.xpath("//android.widget.ImageView[#index='3']");
driver.findElement(path2).click();
Thread.sleep(5000);
Can anyone help? I'm new to this so i'm not very experienced.
Because I can not see the entire XML I can not really tell what you did wrong but probably your xpath is not correct.
With UIAutomatorViewer you can save the XML and then you can test your xpath on it. Either with XMLSpy or an online tool like https://www.freeformatter.com/xpath-tester.html.
Probably there are more android.widget.ImageView with index = 3 and I think appium selects the first one? So you could change your xpath to a more unique one like:
//android.widget.FrameLayout//android.widget.LinearLayout//android.widget.ImageView[#index='3']"
Based on UIAutomator Viewer screen you can also use content-desc as shown below
By path2 = By.xpath("//android.widget.ImageView[contains(#content-desc,'Message')]");
driver.findElement(path2).click();
Bold textStyle attribute of textview in xml is not working after applying custom fonts in app
I have completed developement of an android app. Now I have to change font family for whole app. I have used baskerville-old-face.ttf fonts and used Calligraphy library to apply these fonts into my app.
Following is dependency I have used:
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
Following is the code to initilize Calligraphy library:
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder().setDefaultFontPath("fonts/baskerville.ttf").setFontAttrId(R.attr.fontPath).build());
And following is the code I have used in each Avtivity to use custom fonts:
#Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
It is working fine and all fonts are changed but there is only one problem that text style (bold) is not working with xml attribute. I don't want to change each textview attribute programmatically (Using JAVA code) because there are more than 100 text views in my whole app.
I am not getting what I am doing wrong or what I am missing. Please help !
Your help will be highly appreciated. Thank you.
I am not sure that this is the best answer but I was seen same problem. you can use the baskervilleBold.ttf font in your code instead of baskerville.ttf if there is exist.
i use Google Analytics for monitor my users in my Android app. Now i want to set label's for each activity in google analytics. Just for better understanding i don't want see Activity Class name, instead see my custom label's. how i can do this?
in onCreate:
// Get tracker.
Tracker t = ((MyApplicationClass)
getActivity().getApplication()).getTracker(MyApplicationClass.TrackerName.APP_TRACKER);
// Set screen name. Where path is a String representing the screen name.
t.setScreenName("YOUR_CUSTOM_LABLE_FOR_THIS_SCREEN");
// Send a screen view.
t.send(new HitBuilders.AppViewBuilder().build());
Initialize variable:
private Tracker tracker;
onCreate()
tracker = ((GlobalClass) getApplication()).getTracker(GlobalClass.TrackerName.APP_TRACKER);
tracker.setScreenName("Add_your_own_lable");
tracker.send(new HitBuilders.AppViewBuilder().build());
Hope this will help you.
You can also configure the activity names with XML tracker configuration file.
https://developers.google.com/analytics/devguides/collection/android/v4/#analytics-xml
For example if you like to name "com.example.app.MainActivity" activity as "Home Screen" you can add:
<screenName name="com.example.app.MainActivity">
Home Screen
</screenName>
to the configuration file. When creating the tracker, make sure you are using the XML configuration instead of hardcoded trackerId.
I just started using Google Maps Utils library so that I can have markers with text in them. I understand the library so far and I'm successfully using it. Code snippet:
IconGenerator icnGenerator = new IconGenerator(this);
Bitmap iconBitmap = icnGenerator.makeIcon(item.placeItemName);
myPlaceItemMarkers.add(mMap.addMarker(new MarkerOptions().position(new LatLng(item.latitude, item.longitude))
.icon(BitmapDescriptorFactory.fromBitmap(iconBitmap)).anchor(0.5f, 0.6f)));
Now I started playing around with styling the window a bit and there are two functions that interest me in particular:
icnGenerator.setBackground(Drawable background);
icnGenerator.setTextAppearance(int resid);
I looked up for info on docs and there's only info for BubbleIconFactory which is deprecated. Could someone tell me how to use these 2 functions? I know setTextAppearance is for changing text style but how do I do it? And if I'm not wrong setBackground is for setting custom marker background, but I don't know how to use that either.
I'm still not completely sure how to use setBackground() because I tried using Drawables but it wouldn't work but I figured out how to use setTextAppearance().
I just made a new style:
<style name="iconGenText">
<item name="android:textSize">14sp</item>
<item name="android:textColor">#000000</item>
</style>
And then applied it to IconGenerator:
IconGenerator icnGenerator = new IconGenerator(this);
icnGenerator.setTextAppearance(R.style.iconGenText);
It works as it should.
Set the background like this:
IconGenerator icnGenerator = new IconGenerator(this);
icnGenerator.setBackground(getResources().getDrawable(R.drawable.marker_background));
marker_background has to be a .9.png file. Like the drawables of the library.
It works pretty good for me.
if you're just wanting to change away from the default marker styling without getting fancy you can do this.
icnGenerator.setStyle(IconGenerator.STYLE_BLUE)
There's currently 7 basic styles to select from:
IconGenerator.STYLE_BLUE
IconGenerator.STYLE_DEFAULT
IconGenerator.STYLE_GREEN
IconGenerator.STYLE_ORANGE
IconGenerator.STYLE_PURPLE
IconGenerator.STYLE_RED
IconGenerator.STYLE_WHITE
doc: https://www.javadoc.io/doc/com.google.maps.android/android-maps-utils/latest/com/google/maps/android/ui/IconGenerator.html
I am using the the gridView example from the developer.android.com site. But they are using images saved in the res/drawable folder. I want to try and set the images to come from my web server.
private Integer[] mThumbIds={
for(int i=0;i<myJSONArray.lenght();i++){
Object[] myJSONArray;
setImageDrawable(Drawable.createFromPath(String "www.mywebsite.com: + myJSONArray[i]).thumb);
};
};
Am I on the correct path to accomplish this? I am looking for advice or documentations/tutorials on this process. Thanks in advance.
I modified the GreenDroid library to do it for me - it has a nice set of imageloading classes. It takes some slight modification if you don't want to use their actionbar (I didn't see an easy way to do it without modification). Everything is also async : D !
this way you cant create Drawable from internet, for that you have first download content & make it Drawable refer this