简体   繁体   中英

Change Spinner Text Size Programmatically

have a SeekBar and I get the value of it whenever I scroll it. the position should then be the factor, how big the text in my spinner should be.

So I want to change the text size of my spinner items whenever I scroll not the 50sp as in my layout

My custom_list_row.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textViewRow"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="top|left"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
    android:paddingRight="?android:attr/listPreferredItemPaddingRight"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textSize="50sp" />

My Adapter

ArrayAdapter<Language> adapter = new ArrayAdapter<Language>(this, R.layout.custom_list_row,
                currentLanguages);
        spinnerLanguage.setAdapter(adapter);

the Language class is a Object with a toString method.

@Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        resizeViews(progress);
    }

private void resizeViews(int progress){
    textViewFirstName.setTextSize(20+progress);
    //how can I do this for a spinner here?
}

You can use this.

private void resizeViews(int progress){
textViewFirstName.setTextSize(20+progress);
//this might be helpful
for(int i=0;i<spinnerLanguage.getChildCount();i++){
((TextView)spinnerLanguage.getChildAt(i)).setTextSize(20+progress);
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM