明明写着小写,运行后怎么变成大写了?

YXTS122 2017-04-21 08:04:06


TabDemoActivity.java
package com.example.tabdemo;

import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class TabDemoActivity extends TabActivity {
private TextView tv1,tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.zhu);
TabHost tabHost=getTabHost();
LayoutInflater layoutInflater=LayoutInflater.from(this);
View view=layoutInflater.inflate(R.layout.activity_tab_demo, tabHost.getTabContentView(),true);

tv1=(TextView)view.findViewById(R.id.left);
tv1.setText("这里是one的内容");
TabSpec spec1=tabHost.newTabSpec("tab1");
spec1.setIndicator("admin");
spec1.setContent(R.id.left);
tabHost.addTab(spec1);

tv2=(TextView)view.findViewById(R.id.right);
tv2.setText("这里是two的内容");
TabSpec spec2=tabHost.newTabSpec("tab2");
spec2.setIndicator("user");
spec2.setContent(R.id.right);
tabHost.addTab(spec2);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.tab_demo, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

activity_tab_demo.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

zhu.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.tabdemo.TabDemoActivity" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffc0cb" >

</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ff00" >

</FrameLayout>
</LinearLayout>
</TabHost>

...全文
344 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
YXTS122 2017-05-07
  • 打赏
  • 举报
回复
现在都是用FragmentTabHost代替TabHost了
package com.example.shop;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class MainActivity extends FragmentActivity {
private FragmentTabHost mTabHost;
private LayoutInflater layoutInflater;
private int mImageViewArray[] = { R.drawable.ic_launcher,
R.drawable.abc_ic_clear};
private String mTextViewArray[] = { "首页", "个人中心" };
private Class mFragmentArray[] = { LeftFragment.class, RightFragment.class};


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mai_tab_layout);
initView();
}

private void initView() {
layoutInflater = LayoutInflater.from(this);
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
for (int i = 0; i < 2; i++) {
TabSpec tabSpec = mTabHost.newTabSpec(mTextViewArray[i])
.setIndicator(getTabItemView(i));
mTabHost.addTab(tabSpec,mFragmentArray[i], null);
// mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.selector_tab_background);
}
}

private View getTabItemView(int index) {
View view = layoutInflater.inflate(R.layout.tab_item_view, null);
ImageView imageView = (ImageView) view.findViewById(R.id.imageView1);
imageView.setImageResource(mImageViewArray[index]);
TextView textView = (TextView) view.findViewById(R.id.textView1);
textView.setText(mTextViewArray[index]);
return view;
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}


<LinearLayout 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.shop.MainActivity"
android:orientation="vertical" >

<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" />

<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
</android.support.v4.app.FragmentTabHost>

</LinearLayout>


xiaowenshuma 2017-04-22
  • 打赏
  • 举报
回复
android:textALLCaps="false" 你能加这个属性吗 试试
qxy1547722058 2017-04-21
  • 打赏
  • 举报
回复
表示没发现什么。。。。可能模拟器的问题。

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧