I am learning Android and the following is part of an assignment.
I need to write some text in an Android layout with the first letter in drop caps, like the following text:
I looked up the web and did not find many answers. Is there a style option or some property that I could use?
At the moment, I am thinking of the following options. Please suggest what is the best way to do such a thing
Use an image for the first letter
Write the first letter separately in a big font.
Any suggestions would be helpful.
You can use a RelativeSizeSpan.
final String someText = "A long time ago in a galaxy far, far away";
final SpannableString ss = new SpannableString(someText);
ss.setSpan(new RelativeSizeSpan(5f), 0, 1, 0);
There's a library written by Novoda in which you can add a DropCap https://github.com/novoda/spikes/tree/master/drop-cap
Here's an image from the demo app:
Please follow GitHub sample app
https://github.com/datanapps/CapTextView
<datanapps.captextview.CapTextView
android:id="#+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:padding="5dp"
app:layout_constraintTop_toBottomOf="#+id/text1"
app:capsDropNumber="2"
app:capFont="#font/eb_garamond_regular"
app:capTextColor="#color/purple_700"
app:capTextSize="#dimen/cap_text_size"
app:bodyTextColor="#color/purple_700"
app:bodyTextSize="#dimen/body_text_size"
app:bodyTextFont="#font/eb_garamond_regular"
/>
Hope it will help
Related
I recently implemented Algolia on my app successfully just like the examples.
But the initial search takes about 5 to 7 seconds and I couldn't find a way to make it faster after checking the whole library code and documentation. After the initial search, search becomes very fast.
There is nothing unusual in my implementation but maybe you can see something that I don't. The following code is from the activity where I initialize Algolia:
Searcher searcher = new Searcher(ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY, ALGOLIA_INDEX_NAME);
searcher.setQuery(new Query("word").setExactOnSingleWordQuery(Query.ExactOnSingleWordQuery.ATTRIBUTE));
searcher.addNumericRefinement(new NumericRefinement("CountryId", NumericRefinement.OPERATOR_EQ, 1));
InstantSearch helper = new InstantSearch(this, searcher);
helper.setSearchOnEmptyString(false);
helper.search();
And this is the related xml layout:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="6dp"
android:paddingRight="10dp"
android:paddingLeft="1dp"
android:paddingTop="6dp">
<com.algolia.instantsearch.ui.views.SearchBox
android:id="#+id/searchBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:queryHint="#string/search_text_hint"
algolia:searchIcon="#drawable/icn_search_big"
algolia:closeIcon="#drawable/icn_clear_filled_big"
android:queryBackground="#drawable/sarch_query_shape"
android:background="#drawable/search_shape"
algolia:autofocus="true"
algolia:submitButtonEnabled="false" />
</FrameLayout>`
<com.algolia.instantsearch.ui.views.Hits
android:id="#+id/hits"
android:layout_width="match_parent"
android:layout_height="match_parent"
algolia:autoHideKeyboard="true"
algolia:hitsPerPage="6"
android:layout_below="#+id/searchBarParentLayout"
algolia:infiniteScroll="false"
algolia:itemLayout="#layout/search_item_algolia_row"/>
Do you have any idea what can be the issue here?
I'm glad that the issue disappeared when you switched to another wifi.
For future readers that may encounter network issues with InstantSearch Android:
First of all, build and run one of our demo applications
If you see no problem running the example application, you can try using a proxy like Charles to investigate what's happening between your app and the network
If your problem persists when running the examples, or if you are following the documentation, send an email to support#algolia.com describing the issue with a sample of your code!
So I'm making business card for one local bar and I have run into problem with autoLink.
For some reason, map autoLink does not work with Latvian addresses. I tested same approach with US address (copied the formatting google gave me) and it worked just fine. When I do the same with Latvia addresses autoLink won't respond to it.
Here is my xml code:
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/address"
android:autoLink="map"
android:textSize="16sp"
android:layout_below="#id/about"
android:layout_toRightOf="#id/loc"
android:layout_marginTop="6dp"
/>
And strings code:
<string name="address">Kalēju iela 51, Centra rajons, Rīga, LV-1050, Latvija </string>
I tried writing address in US like format "51 Kaleju Street Riga, LV-1050", but it didn't work. I also tried bunch of other variations that came in my mind, but all unsuccessful.
Maybe someone has experience with this or just knows how to fix this? Maybe some java code is needed?
Thanks in advance,
Sandra.
I'm stuck with the same problem.
But what I found:
"They haven't optimized the android:autoLink maps to India still. Works with US addresses only."
I guess the same goes for Latvia as for India - still doesn't work.
I think we have to use Intents ;(
I want to replace the char ('...') with a string ("...Read more").
Any easy way to do that by extending TextView and overriding a property?
I am expanding the TextView on click by increasing lines from 2 to 500 and vice versa. The TextView is in a ScrollView.
This code is XML File.
<com.google.android.material.textview.MaterialTextView
android:id="#+id/textDescriptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="What is Android ? \nBefore learning all topics of android, it is required to know what is android.Android is a software package and linux based operating system for mobile devices such as tablet computers and smartphones." />
This code is Java file.
String readMore = "... Read more";
String shortDescription = textDescriptions.getText().toString().substring(0, 100);
String text = "<font color=#aaaaaa>"+shortDescription+"</font> <font color=#ff669900>"+readMore+"</font>";
textDescriptions.setText(Html.fromHtml(text));
I need to hide the domain values in a linegraph. Could someone please help me?
plot0.setDomainBoundaries(0, windowsize, BoundaryMode.FIXED);
plot0.addSeries(series0, formatter);
plot0.setDomainStepMode(XYStepMode.INCREMENT_BY_VAL);
plot0.setDrawRangeOriginEnabled(true);
plot0.setTicksPerRangeLabel(5);
plot0.getLegendWidget().setVisible(false);
plot0.getGraphWidget().getBackgroundPaint().setColor(Color.BLACK);
plot0.getGraphWidget().getGridBackgroundPaint().setColor(Color.BLACK);
plot0.setTicksPerDomainLabel(5);
plot0.centerOnRangeOrigin(0);
plot0.setRangeBottomMax(-20);
plot0.setRangeTopMin(20);
plot0.setRangeLowerBoundary(-75, BoundaryMode.FIXED);
plot0.setRangeUpperBoundary(75, BoundaryMode.FIXED);
plot0.setRangeStep(XYStepMode.INCREMENT_BY_VAL, 25);
plot0.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 240);
UPDATE:-
Library version
compile 'com.androidplot:androidplot-core:0.9.7'
I have modified the XML with as below. But the changes are not reflecting unless I modify it inside the code.
<com.androidplot.xy.XYPlotZoomPan
android:id="#+id/dynamicXYPlot0"
androidplot.renderMode="use_background_thread"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="20dp"
android:background="#android:color/black"
ap:backgroundColor="#000000"
ap:borderColor="#000000"
ap:label="Lead I"
ap:domainTickLabelTextColor="#00000000"
ap:domainOriginTickLabelTextColor="#00000000"
ap:gridPaddingBottom="1dp"
ap:labelTextSize="10sp" />
I'd suggest trying to do it in XML by adding these params:
ap:domainTickLabelTextColor="#00000000"
ap:domainOriginTickLabelTextColor="#00000000"
ap:gridPaddingBottom="1dp"
This basically sets the tick label color to be completely transparent and removes the extra padding needed to display those labels below the grid.
Before:
After:
Got the solution. Adding these 2 lines worked.
plot0.getGraphWidget().getDomainTickLabelPaint().setColor(Color.TRANSPARENT);
plot0.getGraphWidget().getDomainOriginTickLabelPaint().setColor(Color.TRANSPARENT);
I am a PHP programmer who is having to do some work in the android development environment. I have 2 books on this and have tried 30 search engine topics and still have not found just a simple example of everything that you need to do to place a working hyperlink in a Java android application.
I just need a very simple but complete ingredient for doing so. I have the 2.2 android development environment with Eclipse and an emulator. I have tried the WebView control which just simply loads a web site into the window when I run the application. I need a basic hyperlink to a web site example.
I don't want anything else thrown in with it (just an application with a working hyperlink and nothing else), because I am trying to learn the different controls bit by bit along with the Java and XML code that controls them.
This is so different from PHP, ASP, etc. that it has me totally fishing for answers. Thanks;
Cullan
Android is a GUI, not a Web browser. Hence, "place a working hyperlink in a Java android application" is akin to "place a snowplow blade on a dishwasher" or "implement a Web app in COBOL". It is technically possible but probably is the incorrect solution to whatever problem it is that you really trying to solve.
So, as MatrixFrog indicates, one possibility is to use a TextView and some HTML:
TextView tv=(TextView)findViewById(R.id.whatever_you_called_it_in_your_layout);
tv.setText(Html.fromHtml("Who knows?"));
But, doing that would be unusual in a GUI environment. Most developers would use a button, or a menu choice, or something along those lines, to trigger viewing some URL.
CommonsWare, That is not what I call a detailed explanation or example of how to place a hyperlink inside an android application. It is just a small snippet of code with no further explanation. I found what works on my own and here is the Java code for it:
package com.practice.weblink;
import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.widget.TextView;
public class WebLink extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textview = (TextView) findViewById(R.id.hyperlink);
Linkify.addLinks(textview, Linkify.WEB_URLS);
}
}
The TextView has the following qualities in the main.xml file:
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/hyperlink"
android:id="#+id/hyperlink"
android:autoLink="web"
>
</TextView>
The strings.xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">WebLink</string>
<string name="hyperlink">http://google.com</string>
</resources>
That is how you give a working example of something. Next time don't assume that people can just piece together what you are mentioning in your answer.
How about using onClick in the XML layout file?
layout.xml
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:clickable="true"
android:text="#string/market_url"
android:textColor="#00f"
android:onClick="openURL"
/>
MyActivity.java
public void openURL(View v) {
String url = ((TextView) v).getText().toString();
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url));
startActivity(intent);
}