我的actionBar出了问题。试着设置一个图标,但仍然是null:/这是代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().setIcon(R.drawable.logo);
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#51717e")));
}
Ofc我的drawable文件夹里有logo。两行都不正确 - 图标和背景颜色。帮助:/
答案 0 :(得分:1)
您的Actionbar为null,因为主题没有ActionBar。
尝试在#photoBox {
-webkit-column-count: 4;
-moz-column-count: 4;
column-count: 4;
-webkit-column-break-inside: avoid; /* Chrome, Safari */
page-break-inside: avoid; /* Theoretically FF 20+ */
break-inside: avoid-column; /* IE 11 */
display:table; /* Actually FF 20+ */
}
#photoBox img{
width: 100% !important;
height: auto !important;
display: block;
}
#photoBox .photo{
position: relative;
float: left;
box-shadow:
0px 0px 0px 2px rgba(0,0,0,0.6),
0px 0px 0px 14px #fff,
0px 0px 0px 18px rgba(0,0,0,0.2),
6px 6px 8px 17px #555;
margin: 25px;
}
#photoBox .title {
position: absolute;
background-color:rgba(255,255,255,0.7);
color: #000;
text-align: center;
font-weight: bold;
width: 100% !important;
bottom: 0;
}
答案 1 :(得分:0)
您需要在ActionBarActivity上调用getSupportActionBar()。不要调用getActionBar() - 这在旧设备上不可用,对于新的r21版appcompat-v7,我希望它一直返回null,因为新的ActionBarActivity禁用并替换了系统操作栏。并在try catch中包围这两行:
try{
getSupportActionBar().setIcon(R.drawable.logo);
getSupportActionBar() .setBackgroundDrawable(new ColorDrawable(Color.parseColor("#51717e")));
}catch(NullPointerException e)
{
e.printstacktrace();
}
答案 2 :(得分:0)
试试这个:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();