在Android的所有屏幕中都可以看到额外的后退按钮

时间:2016-11-24 13:37:31

标签: android

1)如何删除额外的黑色箭头按钮?它显示在所有页面中。但白色箭头按钮仅处于活动状态。按下白色按钮时,它可以返回。

enter image description here

2)如何设置带有后退按钮的操作栏,首先是标题?

2 个答案:

答案 0 :(得分:1)

ActionBar actionBar= getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(false); 尝试将此放在onCreate方法的顶部,这将禁用应用程序的默认工具栏按钮,然后您可以创建自己的工具栏并添加它,但这是一个完整的其他过程,这个答案只会隐藏您的图标和标题,这是自动出现

答案 1 :(得分:0)

我附上了我的代码..

MainActivity.java

#include  <stdio.h>
#include  <stdlib.h>
#include  <sys/socket.h>
#include  <sys/types.h> 
#include  <netdb.h>
#include  <string.h>
#include  <arpa/inet.h>

#define     SUCCESS 0
#define     FAILURE -1

int main(int argc, char *argv[])
{
if(argc != 2) {
    printf("./a.out <domain>\n");
    return FAILURE;
}
struct addrinfo src,*res,*var;
struct sockaddr_in *ipv4;
struct sockaddr_in6 *ipv6;
char ipstr[INET6_ADDRSTRLEN];
int status;
void *addr;
src.ai_family=AF_UNSPEC;
src.ai_socktype=SOCK_STREAM;
src.ai_flags=AI_PASSIVE;
if((status = getaddrinfo(argv[1],NULL,&src,&res))!=0) {
    fprintf(stderr,"getaddrinfo error:%s\n",gai_strerror(status));
    exit(1);
}
for(var = res;var != NULL;var = var->ai_next) {
    if(var->ai_family == AF_INET) {
        ipv4 = (struct sockaddr_in *) var->ai_addr;
        addr = &(ipv4->sin_addr);
    }
    else {
        ipv6 = (struct sockaddr_in6 *) var->ai_addr;
        addr = &(ipv6->sin6_addr);
    }
    inet_ntop(var->ai_family,addr,ipstr,INET6_ADDRSTRLEN);
    printf("IP address:%s\n",ipstr);
}
freeaddrinfo(res);
freeaddrinfo(var);
return SUCCESS;
}

activity_main.xml中

public class MainActivity extends AppCompatActivity implements View.OnClickListener {     
        Toolbar toolbar;
                @Override
                    protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_main);
                        toolbar = (Toolbar) findViewById(R.id.toolbar);
                        setSupportActionBar(toolbar);
                        getSupportActionBar().setTitle("");
                        getSupportActionBar().setDisplayShowTitleEnabled(true);
                        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
                        getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(false);
                }

                    public void showFragment(Fragment fragment, String back_stack_name, boolean isAddToBackStack) {
                        FragmentTransaction transaction = getFragmentManager().beginTransaction();
                        transaction.add(R.id.container, fragment);
                        if (isAddToBackStack) {
                            transaction.addToBackStack(back_stack_name);
                        }
                        transaction.commit();
                    }

                    @Override
                    public void onBackPressed() {
                        if (getFragmentManager().getBackStackEntryCount() == 0) {
                            showAlertDialog(Constants.EXIT_APP, Constants.APP_NAME);
                        } else {
                            getFragmentManager().popBackStackImmediate();
                        }
                    }
    }