I created a splashscreen for my react-native app and have to implement TextView with custom fonts.
I created an Android layout specifically for the splashscreen with res/layout/launch_screen.xml and the TextViews appears but without custom fonts then i launch that on splashActivity file.
But it's strange because when i inject the layout directly on the mainActivity file the fonts seems be loaded.
So i think it's due to the fonts path in SplashActivity file but the code seems be ok.
Here are the files :
SplashActivity.js :
package com.app;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.graphics.Typeface;
import android.content.res.AssetManager;
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.launch_screen);
TextView txt_1 = (TextView) findViewById(R.id.din_bold);
Typeface font_1 = Typeface.createFromAsset(getAssets(), "fonts/DinCondBold.otf");
txt_1.setTypeface(font_1);
TextView txt_2 = (TextView) findViewById(R.id.din_light);
Typeface font_2 = Typeface.createFromAsset(getAssets(), "fonts/DinCondLight.otf");
txt_2.setTypeface(font_2);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
MainActivity.js
package com.app;
import android.app.Activity;
import com.facebook.react.ReactActivity;
import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
public class MainActivity extends ReactActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SplashScreen.show(this, R.style.SplashScreenTheme);
}
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "app";
}
}
And launch_screen.xml
<LinearLayout 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:background="#drawable/background"
android:gravity="center"
android:orientation="vertical"
tools:context="com.mitsu.MainActivity">
<TextView
android:id="#+id/din_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCAN PRODUITS"
android:textColor="#eb212e"
android:textSize="36sp"
android:textStyle="bold" />
<TextView
android:id="#+id/din_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BIENVENUE"
android:textColor="#717171"
android:textSize="36sp" />
<ImageView
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_marginTop="14dp"
android:src="#drawable/splash_logo" />
</LinearLayout>
Does anyone know what's going on?
Related
I want to select multiple items in spinner but getting runtime exception due to java.lang.CastException in XML file
XML:
<com.example.lenovo.abc.MultiSpinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/hobby"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:layout_weight="0.91"
/>
MultiSpinner class:
Android Spinner with multiple choice
About class
package com.example.lenovo.abc;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import java.util.Arrays;
import java.util.List;
public class About extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
TextView intro= (TextView) findViewById(R.id.introducing);
MultiSpinner hobby= (MultiSpinner) findViewById(R.id.hobby);
List<String> h = Arrays.asList(getResources().getStringArray(R.array.hobby));
hobby.setItems(h,"Hobbies", (MultiSpinner.MultiSpinnerListener) this);
}
}
hobby.setItems(h,"Hobbies", (MultiSpinner.MultiSpinnerListener) this);
You are not implementing MultiSpinner.MultiSpinnerListener in this activity and passing context casting to MultiSpinner.MultiSpinnerListener. Try implementing the listener in this activity.
I'm trying to get a ListView to show the contents of a simple array but my program crashes at the setAdapeter line. As I understand this is supposed to be because the final value comes out as null but I don't see why that would be the case or how to fix it. I have already tried using ArrayAdapeter instead as well as catching the null exception with a try block. The former changes nothing and the latter simply shows a blank activity with no list to speak of. Please help.
Here's Main Activity
package ballton.fowdeckbuilder;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ArrayAdapter;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnDecks = (Button) (findViewById(R.id.btnDecks));
Button btnCards = (Button) (findViewById(R.id.btnCards));
btnDecks.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, DeckCatalogue.class));
}
});
btnCards.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, CardCatalogue.class));
}
});
}
}
Here's the activity with the Problem
package ballton.fowdeckbuilder;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
public class DeckCatalogue extends AppCompatActivity {
ListView Ldecks;
String TAG = "TAG";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deck_catalogue);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Ldecks = (ListView) (findViewById(R.id.DeckList));
String Decks[] = new String[] {"Faria","Melgis"};
ListAdapter feed = (new ArrayAdapter<String>(this, R.layout.show_deck, Decks));
Ldecks.setAdapter(feed);
}
}
Here's the Layout for that activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="ballton.fowdeckbuilder.DeckCatalogue"
tools:showIn="#layout/activity_deck_catalogue">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/DeckList"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
And Here's the layout XML I use for the list times
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/Deck" />
</LinearLayout>
Use this code instead of yours:
ListAdapter feed = (new ArrayAdapter<String>(this, R.layout.show_deck, R.id.Deck, Decks));
This happened because you must supply the resource ID (as your xml: R.id.Deck) for the TextView you used for ListView.
Friends I just Wanna set Custom Typeface Form my assets/fonts folder
My Java Code Looks like this
package customtext;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
public class Custom extends Dialog implements android.view.View.OnClickListener{
public Custom(Context context) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom);
btn=(Button) findViewById(R.id.dismis_dialog);
btn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
dismiss();
}
}
When I try to add like this Its not worked for me
its giving error
here this is my XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
style="#style/Theme.CustomDialog" >
<FrameLayout
android:layout_width="250sp"
android:layout_height="70sp"
android:background="#ee8f03" >
<TextView
android:layout_width="180sp"
android:layout_height="wrap_content"
android:id="#+id/sharedialog"
android:text="#string/msg"
android:textColor="#272b2d"
android:background="#ef8e01"
android:layout_gravity="center" >
</TextView>
</FrameLayout>
<FrameLayout
android:layout_width="250sp"
android:layout_height="70sp"
android:background="#fff" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:clickable="true"
android:id="#+id/dismis_dialog"
android:text="#string/dismis"/>
</FrameLayout>
</LinearLayout>
Would you please tell how to add custom font to this type of context Dialog Box
Thank you
check out this links for creating Custom Dialog
http://www.mkyong.com/android/android-custom-dialog-example/
also you can set the custom font like this way
Typeface type = Typeface.createFromAsset(getAssets()/fonts, "myfonts.ttc");
youTextView.setTypeface(type);
put your fonts into fonts folder under assets dir
Try this
Typeface type = Typeface.createFromAsset(getAssets(), "name.ttc");
dismis_dialog.setTypeface(type);
sharedialog.setTypeface(type);
I have this code:
package com.problemio;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class ProblemioActivity extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button addProblemButton = (Button)findViewById(R.id.add_problem_button);
Button browseProblemsButton = (Button)findViewById(R.id.browse_problems_button);
Button searchProblemsButton = (Button)findViewById(R.id.search_problems_button);
Button myProblemsButton = (Button)findViewById(R.id.my_problems_button);
addProblemButton.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v) {
Intent myIntent = new Intent(ProblemioActivity.this, AddProblemActivity.class);
ProblemioActivity.this.startActivity(myIntent);
}
});
}
}
It compiles fine and displays the addProblemButton button, but when that button is clicked, the system gives a runtime exception.
Here is the AddProblemActivity class:
package com.problemio;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class AddProblemActivity extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//TextView text = (TextView) dialog.findViewById(R.id.addProblemText);
//text.setText(R.string.addProblemText);
TextView tv = new TextView(this);
tv.setText("Please Add a Problem");
setContentView(tv);
}
}
and here is the layout main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="First, add the problem you want to solve!"
/>
<TextView
android:id="#+id/add_problem_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add a Problem You Want To See Solved"
/>
<Button
android:id="#+id/add_problem_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add a Problem"
/>
<Button
android:id="#+id/browse_problems_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Browse Problems"
/>
<Button
android:id="#+id/search_problems_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Search Problems"
/>
<Button
android:id="#+id/my_problems_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="View My Problems"
/>
</LinearLayout>
any idea what might be going wrong? By the way, I can't seem to locate the stack trace of the exception. Where should I look for that in Eclipse? All it currently shows me is AndroidRuntimeException - dalvik.system.NativeStart.main
Thanks!!
The only problem I can think of is that your Activity "AddProblemActivity" is not register in the manifest.
See the logs under LogCat...you will find it in Window >Show View >Android > LogCat
is it possible to set the Content of my Listview to an other Activity.
Something like i've done here with my tabhost-content.
package de.retowaelchli.filterit;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
import android.content.Intent;
public class StatsActivity extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stats);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Smiley Filter").setContent(new Intent(this, SFilterStatsActivity.class)));
tabHost.setCurrentTab(1);
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Auto Delete").setContent(new Intent(this, ADFilterStatsActivity.class)));
}
}
So, i just want to set the content of my ListView to an other Activity. Is that possible, i've yes how can i do that?
Thx in Advance!
Best Regards
safari
Some more information to understand, i'd like to realize that in this ACtivity:
package de.retowaelchli.filterit;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class ADeleteActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.autodelete);
}
/** Verweise auf die anderen Seiten **/
public void onClickADConfig(View view){
final Intent i = new Intent(this, ADFilterConfigActivity.class);
startActivity(i); }
}
Here's the Layout for it:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<ListView android:id="#+id/AutoDeleteFilterListe"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.97">
</ListView>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/ADOverviewMainsite"
android:layout_weight="0.03">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ADFilterOverview"
android:onClick="onClickADConfig"
android:layout_weight="0.03">
<TextView
android:text="#string/newadfilter"
style="#style/NormalFont" />
</TableRow>
</TableLayout>
</LinearLayout>
I WANT in this activity to set the Content of my Listview to an other .class. I hope you guys understand what i mean. :=)
I found out that it isn't possible to set the Content of a ListView to an other activity. Greetz safari