操作栏 - 自定义图像和文本附近向上按钮自定义、按钮、图像、文本

2023-09-12 03:27:24 作者:没有伞的孩子必须努力奔跑

我有我的应用程序两个选项的登录屏幕 - 登录和创建账户。我想要实现如下的东西,例如,在登录屏幕:

I have a login screen with two options in my app - "login" and "create account". I want to implement the following thing, for example, on login screen :

我有一个活动,另外,通过点击UP按钮,我想返回。我有希望的活性的下面的构造:

I've got one activity and another, by tapping on "UP" button i want to return back. I have the following constructor of desired activity:

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bl__login_form_view_controller);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    //----------------------added source - no effect-----------------------

    getActionBar().setDisplayShowHomeEnabled(true);
    getActionBar().setIcon(R.drawable.circle) ;
    getActionBar().setTitle("A title");


    //---------------------------------------------------------------------
    setTitle ("Вход") ;
}

和我有UP键。如何添加圆图像和一些文字?所有教程说,那我可以设置应用程序图标在AppManifest,但它会改变主屏幕上的应用程序图标。我怎么能添加文字后退按钮?我不想实现任何导航逻辑或设置父活动为整个应用程序,因为它是一个登录界面,只有经过授权的导航逻辑的主菜单将显示。在此先感谢!

And i have UP button. How can i add circle image and some text? All tutorials say, that i can set app icon in AppManifest, but it would change app icon on main screen. And how can i add text to back button? I don't wanna implement any navigation logic or set parent activity for whole app, because it's a login screen, and the main menu with the navigation logic will be shown only after authorization. Thanks in advance!

推荐答案

的setTitle 将设置标题和的setIcon 将设置图标动作条

setTitle will set the title and setIcon will set the icon to the ActionBar.

getActionBar().setTitle("Your Title");
getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setIcon(R.drawable.youricon);

参考:加起来行动和的 http://developer.android.com/guide/topics/ui/actionbar.html