java - configuration of TabHost using getDrawable -
i have problem when calling getdrawable() in mainactivity, i'm done activity_main.xml, shows warning "the method getdrawable(int) type resources deprecated".
can me?
mainactivity.java:
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); resources res= getresources(); tabhost tabs = (tabhost) findviewbyid(android.r.id.tabhost); tabs.setup(); tabhost.tabspec spec = tabs.newtabspec("pestana 1"); spec.setcontent(r.id.tab1); spec.setindicator("1",res.getdrawable(android.r.drawable.bottom_bar)); tabs.addtab(spec); tabs.setup(); tabhost.tabspec spec1 =tabs.newtabspec("pestana 2"); spec1.setcontent(r.id.tab2); spec.setindicator("2",res.getdrawable(android.r.drawable.btn_minus)); tabs.addtab(spec1); tabs.setup(); tabhost.tabspec spec2 =tabs.newtabspec("pestana 3"); spec2.setcontent(r.id.tab3); spec.setindicator("3",res.getdrawable(android.r.drawable.btn_radio)); tabs.addtab(spec2); } } activity_main.xml:
<relativelayout 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" tools:context="com.example.tabhost1.mainactivity"> <tabhost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <tabwidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="100dp"></tabwidget> <framelayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <linearlayout android:id="@+id/tab1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="pestana 1"></textview> </linearlayout> <linearlayout android:id="@+id/tab2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="pesana 2"></textview> </linearlayout> <linearlayout android:id="@+id/tab3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="pesana 3"></textview> </linearlayout> </framelayout> </linearlayout> </tabhost>
can me?
there nothing wrong calling getdrawable(). ~99% of android devices, option.
in android 5.1, added a second getdrawable() method, 1 takes theme second parameter. marked single-parameter version of getdrawable() deprecated.
if minsdkversion 22, use two-parameter version of getdrawable().
if minsdkversion less 22, continue using single-parameter version of getdrawable(), , live deprecation notice.
Comments
Post a Comment