【发布时间】:2014-12-24 16:56:18
【问题描述】:
我想更改 ActionBar 主页按钮的左填充。我试过this 解决方案。但是当我尝试findViewById(android.R.id.home) 时,我得到了空值。同时android.R.id.home 不为0。
只有当我使用 android-suppot-v7 时才会发生这种情况。如果我不使用支持库,一切都会好起来的。
也许有人可以帮助我?
这是我的简单代码:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
ImageView view = (ImageView)findViewById(android.R.id.home);
if (view !=null){
view.setPadding(10, 0, 0, 0);
}
}
}
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.timoshkois.actionbar.MainActivity">
</RelativeLayout>
【问题讨论】:
-
你试过用 MenuItem 代替 ImageView 吗?
-
@RenanLopesFerreira 在任何情况下都会返回 null
-
您找到解决方案了吗?我也面临同样的问题。
-
我面临同样的问题。如果您发现了什么,愿意分享吗?
-
@AndreiN。没找到
标签: android android-actionbar android-support-library