【问题标题】:Title of the selected tab disappearing after screen orientation change屏幕方向更改后所选选项卡的标题消失
【发布时间】:2014-05-22 02:31:33
【问题描述】:

我使用 android:configChanges 来不重新创建方向更改的活动,并且所有工作都运行良好,除了一件事,所选选项卡的标题在更改后消失,我不知道为什么。为了为特定选项卡设置警告,我让我的选项卡(actionbar.tab)获得了自定义视图,也许问题就在这里。 我用 logcat 做了一些测试,文本仍然在 textview 上。

 @Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

    Log.e("irc", "Printing all the tab titles");

    for (int i = 0; i < actionBar.getTabCount(); i++) {
        ActionBar.Tab tab = actionBar.getTabAt(i);
        String texttab = ((TextView) tab.getCustomView().findViewById(
                R.id.tabtitle)).getText().toString();
        Log.e("irc", "Tab on " + i + ": " + texttab);
    }
// THE LOGCAT PRINTS ALL THE TAB TITLE, INCLUDING THE MISSING TITLE
}

在 Textview 上也尝试过 View.VISIBLE 和 setTextColor()。

public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    RelativeLayout relative = (RelativeLayout) actionBar.getSelectedTab()
            .getCustomView();

    TextView tv = (TextView) relative.findViewById(R.id.tabtitle);

    tv.setVisibility(View.VISIBLE);
    tv.setTextColor(Color.WHITE);

//DOESNT WORK

}

标签自定义布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="64dip"
android:layout_marginLeft="-3dip"
android:layout_marginRight="-3dip"
android:layout_weight="1"
android:orientation="vertical" >

<TextView
    android:id="@+id/tabtitle"
    style="?android:attr/tabWidgetStyle"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true" />

</RelativeLayout>

更改前的活动: https://www.dropbox.com/s/m7ntqk7h4g9vraq/2014-05-16%2003.33.09.png

更改后的活动: https://www.dropbox.com/s/iltbsfcgfraowri/2014-05-16%2003.33.16.png

提前感谢您的帮助。

更新

我在操作栏上添加选项卡的活动方法。

public void addPVTTab(String title) {
    MyService.log("Adicionando tab " + title + ".");
    Tab tab = actionBar
            .newTab()
            .setCustomView(createTabCustomView(title))
            // .setText(title) customview
            .setTabListener(
                    new MyTabListener<ChatFragment>(this, title,
                            ChatFragment.class));
    actionBar.addTab(tab);

}

private RelativeLayout createTabCustomView(String title) {

    RelativeLayout view = (RelativeLayout) getLayoutInflater().inflate(
            R.layout.tabtitle_layout, null);

    ((TextView) view.findViewById(R.id.tabtitle)).setText(title);

    return view;

}

在此过程中的任何时候,只要其他用户向我发送新的私人消息,都可以调用它。

【问题讨论】:

  • 如果您将方向改回纵向(在横向并且标题消失之后),标题会恢复还是丢失?
  • 一旦消失,就不会再出现。但我刚刚发现,如果我关闭活动并重新打开(我的应用程序是基于服务的并且状态已恢复),它会再次出现。但是,如果我再次改变方向,就会消失。
  • 你是在oncreate中动态设置标题吗?
  • 我正在发布方法。
  • 很高兴开发了世界上第一个不兼容横向的应用程序:)

标签: android tabs textview screen-orientation


【解决方案1】:

我发现了问题,我遇到了这个错误:https://code.google.com/p/android/issues/detail?id=41392

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多