gpt4 book ai didi

android - 无法以编程方式访问 Action Bar 项目 View - Android

转载 作者:行者123 更新时间:2023-11-29 19:07:34 26 4
gpt4 key购买 nike

我的代码(在onCreate() 方法中:

    ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(true);
LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.main_action_bar, null);

actionBar.setCustomView(v);

profilePictureView = (ProfilePictureView) v.findViewById(R.id.userProfilePicture);

然后,当我尝试使用以下方法以编程方式更改 View 时:

profilePictureView.setProfileId(null);

我收到错误消息“无法在 null 引用上调用 setProfileId

我应该如何正确访问该 View 。

最佳答案

如果您不介意的话,可以帮我做一下,然后告诉我它是否有效。

class YourActivity extends AppCompatActivity{
//simply use getSupportActionBar() and check
getSupportActionBar().setDisplayShowCustomEnabled(true);
LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.main_action_bar, null);

profilePictureView = (ProfilePictureView) v.findViewById(R.id.userProfilePicture);

profilePictureView.setProfileId(null);

// declaring it here because you are setting the whole view in the actionbar now after adding the profile pic and all. So may it is a reason it is not been able to find out the actionbar to be applied on
getSupportActionBar().setCustomView(v);
}

关于android - 无法以编程方式访问 Action Bar 项目 View - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46614037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com