Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 自定义操作栏不充气_Android_Android Layout_Android Actionbar_Android Xml - Fatal编程技术网

Android 自定义操作栏不充气

Android 自定义操作栏不充气,android,android-layout,android-actionbar,android-xml,Android,Android Layout,Android Actionbar,Android Xml,我正在尝试自定义操作,但它不起作用。我几乎完全按照邮局的指示去做,但它不起作用。这是我的操作栏(action\u bar\u table.xml)的布局文件: 这看起来很简单,但我不知道为什么它不起作用。有人能帮我吗 提前感谢:) 编辑1: 下面是string.xml文件: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">The Commuter Chica

我正在尝试自定义操作,但它不起作用。我几乎完全按照邮局的指示去做,但它不起作用。这是我的操作栏(
action\u bar\u table.xml
)的布局文件:

这看起来很简单,但我不知道为什么它不起作用。有人能帮我吗

提前感谢:)

编辑1:

下面是
string.xml
文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">The Commuter Chicago</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="lines">Lines</string>
<string name="stops">Stops</string>
<string name="arrivals">Arrivals</string>
<string-array name="lines">
    <item>Red</item>
    <item>Blue</item>
    <item>Brown</item>
    <item>Green</item>
    <item>Orange</item>
    <item>Purple</item>
    <item>Pink</item>
    <item>Yellow</item>
</string-array>

</resources>

芝加哥通勤者
你好,世界!
设置
线
停止
到达
红色
蓝色
棕色的
绿色
橙色
紫色
粉红色
黄的

如果您的
活动是
ActionBarActivity

 @Override  protected void onCreate(Bundle savedInstanceState)   { 
super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_pager_and_easmain);

setContentView(R.layout.activity_main);

  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

 getSupportActionBar().setCustomView(R.layout.action_bar_tablet);
并将代码更改为检查

if (findViewById(R.id.container) != null) {
不要检查它,只需在setContent()方法之后初始化Actionbar

亲爱的更改您的代码并完成此操作。 @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ActionBar mActionBar=getActionBar(); mActionBar.setDisplayShowHomeEnabled(false); mActionBar.setDisplayShowTitleEnabled(假); LayoutInflater mInflater=LayoutInflater.fr`在此处输入代码`om(this); View mCustomView=mInflater.充气(动作条片,空); TextView mTitleTextView=(TextView)
mCustomView.findViewById(R.id.title\u text); mTitleTextView.setText(“我自己的标题”); ImageButton ImageButton=(ImageButton)mCustomView .findViewById(R.id.imageButton); setOnClickListener(新的OnClickListener(){ @凌驾 公共void onClick(视图){ Toast.makeText(getApplicationContext(),“刷新已单击!”, Toast.LENGTH_LONG).show(); } }); mActionBar.setCustomView(mCustomView); mActionBar.setDisplayShowCustomEnabled(true); } [在此处输入链接说明][1] [1]: http://javatechig.com/android/actionbar-with-custom-view-example-in-android
你想在动作栏中放置微调器吗?是的,我正在尝试。你能发布你的strings.xml吗?@DanielNugent我添加了一个编辑。谢谢。我在试着看看我能不能让它工作。我还发现了这些帖子:这是:只需要使用getSupportActionBar()而不是我所拥有的!非常感谢你的帮助!
 @Override  protected void onCreate(Bundle savedInstanceState)   { 
super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_pager_and_easmain);

setContentView(R.layout.activity_main);

  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

 getSupportActionBar().setCustomView(R.layout.action_bar_tablet);
if (findViewById(R.id.container) != null) {
Dear change your code and fellow this.  
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActionBar mActionBar = getActionBar();
        mActionBar.setDisplayShowHomeEnabled(false);
        mActionBar.setDisplayShowTitleEnabled(false);
        LayoutInflater mInflater = LayoutInflater.fr`enter code here`om(this);
        View mCustomView = mInflater.inflate(action_bar_tablet, null);
        TextView mTitleTextView = (TextView) <br>             mCustomView.findViewById(R.id.title_text);
        mTitleTextView.setText("My Own Title");

        ImageButton imageButton = (ImageButton) mCustomView
                .findViewById(R.id.imageButton);
        imageButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                Toast.makeText(getApplicationContext(), "Refresh Clicked!",
                        Toast.LENGTH_LONG).show();
            }
        });

        mActionBar.setCustomView(mCustomView);
        mActionBar.setDisplayShowCustomEnabled(true);
    }
[enter link description here][1]


  [1]: http://javatechig.com/android/actionbar-with-custom-view-example-in-android