텝호스트에서 밑에 버튼의 높이를 변경하고 싶은데 어떻게 하나요...?
자바 코드에서 버튼을 누르면 높이를 변경하고 싶습니다.
btnColor를 누르면 색이 변경되고(이건 잘됨), btnHeight를 누르면 높이가 변경되게 하고싶습니다.
public class MainActivity extends TabActivity {
private TabHost tabHost;
private Button btnColor,btnHeight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnColor = findViewById(R.id.btnColor);
btnHeight = findViewById(R.id.btnHeight);
tabHost = getTabHost();
TabHost.TabSpec Spec1 = tabHost.newTabSpec("TAG1").setIndicator("1번");
Spec1.setContent(R.id.test1);
tabHost.addTab(Spec1);
TabHost.TabSpec Spec2 = tabHost.newTabSpec("TAG2").setIndicator("2번");
Spec2.setContent(R.id.test2);
tabHost.addTab(Spec2);
tabHost.setCurrentTab(0);
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#ff0000"));
}
});
btnHeight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for(int idx=0; idx<tabHost.getTabWidget().getChildCount(); ++idx){
tabHost.getTabWidget().getChildAt(idx).getLayoutParams().height=150;
}
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<TabHost 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:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:id="@+id/test1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btnColor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="배경색 변경" />
</LinearLayout>
<LinearLayout
android:id="@+id/test2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btnHeight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="높이변경" />
</LinearLayout>
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f00fff">
</TabWidget>
</LinearLayout>
</TabHost>