Java 使用getDrawable配置TabHost
我在MainActivity中调用getDrawable时遇到问题,我已经使用activity_main.xml完成了,但它显示了此警告—类型资源中的getDrawableint方法已被弃用 有人能帮我吗 MainActivity.java: activity_main.xml: 有人能帮我吗 调用getDrawable没有什么错。对于约99%的Android设备,这是您唯一的选择 在安卓5.1中,他们补充道。然后,他们将getDrawable的单参数版本标记为已弃用 如果minSdkVersion为22,则使用getDrawable的双参数版本 如果minSdkVersion小于22,请继续使用getDrawable的单参数版本,并使用弃用通知Java 使用getDrawable配置TabHost,java,android,eclipse,drawable,Java,Android,Eclipse,Drawable,我在MainActivity中调用getDrawable时遇到问题,我已经使用activity_main.xml完成了,但它显示了此警告—类型资源中的getDrawableint方法已被弃用 有人能帮我吗 MainActivity.java: activity_main.xml: 有人能帮我吗 调用getDrawable没有什么错。对于约99%的Android设备,这是您唯一的选择 在安卓5.1中,他们补充道。然后,他们将getDrawable的单参数版本标记为已弃用 如果minSdkVersi
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);
}
}
<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>