Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems increasing text size in my app
    primarykey
    data
    text
    <p>I'm trying to increase the size of a particular textview from within the app. I would like to do it via a menu item selection but am having problems. I have tried the following:</p> <pre><code>@Override public boolean onCreateOptionsMenu(Menu menu) { // Create an options menu for the activity super.onCreateOptionsMenu( menu ); incrseTxtMenu = menu.add( 0,4,0,"Increase Text Size" ); incrseTxtMenu.setIcon( R.drawable.ic_menu_plus ); incrseTxtMenu.setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // handler.sendMessage( handler.obtainMessage() ); TextView tempTxt = getTextView(); tempTxt.setTextSize( 25 ); return true; } }); return true; } </code></pre> <p>But this is throwing a null pointer exception. I also tried just using intro.setTextSize() but it throws the same error. How can I access the textview from within this menu item? </p> <p>**Update</p> <pre><code>//Method used to fetch the textview public TextView getTextView() { return intro; } </code></pre> <p>And the error from log cat:</p> <pre><code>AndroidRuntime FATAL EXCEPTION: main java.lang.NullPointerException at android.omni.Artist_activity$1.handleMessage( Artist_activity.java:32 ) </code></pre> <p>Also btw - I'm trying to use a handler to update the GUI - am I correct in assuming that this is necessary right?</p> <p>**Update 2 XML CODE</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id = "@+id/tab_one_top_level" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:orientation = "vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TextView android:id = "@+id/faq_Intro" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "@string/faq_Intro" android:typeface = "monospace" android:textStyle = "bold" android:paddingBottom = "12dp" /&gt; &lt;TextView android:id = "@+id/faq_Intro_Info" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "@string/faq_Intro_Info" android:textSize = "10dp" android:typeface = "monospace" android:textStyle = "bold" /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>Any thoughts?</p> <p><strong><em>My Code Solution</em></strong></p> <pre><code>@Override public boolean onCreateOptionsMenu(Menu menu) { // Create an options menu for the activity super.onCreateOptionsMenu( menu ); incrseTxtMenu = menu.add( 0,1,0,"Increase Text Size" ); incrseTxtMenu.setIcon( R.drawable.ic_menu_plus ); decrseTxtMenu = menu.add( 0,2,0,"Decrease Text Size" ); decrseTxtMenu.setIcon( R.drawable.ic_menu_negate ); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Increase size menu item if( item.getItemId() == 1 ) { intro.setTextSize( myIntroSize += 5 ); introInfo.setTextSize( myIntroInfoSize += 5 ); } // Derease size menu item else if( item.getItemId() == 2 ) { intro.setTextSize( myIntroSize -= 5 ); introInfo.setTextSize( myIntroInfoSize -= 5 ); } return true; } </code></pre> <p>The onCreate() method simply initialises the textview as before. Oh and the values of myIntroSize and myIntroInfoSize can be whatever you want.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload