2010-04-02 74 views

回答

16

做到这一点的最简单的方法,恕我直言,是摆脱(在清单中的<activity>元素android:theme="@android:style/Theme.NoTitleBar")标准的标题栏,并把自己的“标题栏”顶部的活动。

但请注意,“标题栏中的按钮”风格更多是iPhone-ish。 Android通常会在选项菜单中显示,所以UI不那么混乱(以刷新两次为代价)。

+6

有趣的是,Android的现在都提倡的包容一致的标题栏 - 按钮用于重复操作。例如,请参阅Google I/O 2010应用程序和Twitter用户界面设计模式博客文章:http://android-developers.blogspot.com/2010/05/twitter-for-android-closer-look-at.html – 2010-05-30 22:14:17

1

我认为更好的方法是简单地刷新视图,如果它通过使用处理程序是活动的。如果您在活动恢复时拉动内容,那么您在任何时候离开并回到视图时都会刷新。如果您希望用户坐在视图的顶层并需要更新信息,则可以使用延迟处理程序处理此问题,该处理程序将调用您的恢复方法并定期刷新视图,从而不需要按钮。

Here是处理程序类文档的链接。我将首先看看处理程序的基本用法。然后测试sendMessageDelayed方法,以便在每次调用结束时重新启动处理程序。另外,如果您的活动是最重要的活动,请务必只创建一个新的处理程序,如果不是,则不要打扰刷新ui。在暂停和恢复时添加一个简单的isActive标志是一种体面的检查方法。

+1

你假设无限数据计划。并非每个人都有无限的数据计划其他人支付兆字节。自动刷新作为一个选项很酷;自动刷新,因为* only选项*不够酷。 – CommonsWare 2010-04-03 11:04:17

3

你为什么不试试这个

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    final boolean customTitle= requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 

    setContentView(R.layout.main); 

    if (customTitle) { 
     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, Set your layout for title here and mention your button in this layout); 
    } 

    final TextView myTitleText = (TextView) findViewById(R.id.myTitle); 
    if (myTitleText != null) { 
     myTitleText.setText("NEW TITLE"); 
     myTitleText.setBackgroundColor(Color.BLUE); 
    } 
} 
3

没错这solveed一个问题,我已经...修剪版本低于...

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 

    setContentView(R.layout.main); 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, Set your layout for title here and mention your button in this layout); 

    final TextView myTitleText = (TextView) findViewById(R.id.myTitle); 
    if (myTitleText != null) { 
     /* your code here */ 
    } 
} 
相关问题