<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Keyboard &#8211; Pauls Blog</title>
	<atom:link href="https://sterl.org/tag/keyboard/feed/" rel="self" type="application/rss+xml" />
	<link>https://sterl.org</link>
	<description></description>
	<lastBuildDate>Tue, 09 Sep 2025 12:05:25 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>Android show Keyboard by default</title>
		<link>https://sterl.org/2016/02/android-show-keyboard-by-default/</link>
					<comments>https://sterl.org/2016/02/android-show-keyboard-by-default/#comments</comments>
		
		<dc:creator><![CDATA[Paul Sterl]]></dc:creator>
		<pubDate>Fri, 26 Feb 2016 15:36:14 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Dialog]]></category>
		<category><![CDATA[DialogFragment]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Keyboard]]></category>
		<category><![CDATA[Problem]]></category>
		<category><![CDATA[Show Keyboard]]></category>
		<guid isPermaLink="false">http://sterl.org/?p=144</guid>

					<description><![CDATA[Problem Sometimes we the Keyboard doesn&#8217;t show up by default if we e.g. open a dialog and request the focus for an input element. Even following the default tutorials doesn&#8217;t really help. As soo here some samples how it will show up. Solution Show Keyboard in Dialogs / DialogFragment Usually the solution the the Android&#8230;]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Problem</h2>



<p>Sometimes we the Keyboard doesn&#8217;t show up by default if we e.g. open a dialog and request the focus for an input element. Even following the default tutorials doesn&#8217;t really help. As soo here some samples how it will show up.</p>



<h2 class="wp-block-heading">Solution</h2>



<h3 class="wp-block-heading">Show Keyboard in Dialogs / DialogFragment</h3>



<p>Usually the solution the the <a href="https://github.com/codepath/android_guides/wiki/Using-DialogFragment" target="_blank" rel="noopener">Android Guide</a>&nbsp;&nbsp;just works using:</p>



<h4 class="wp-block-heading">Solution 1</h4>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Java&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}">@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  // Get field from view
  mEditText = (EditText) view.findViewById(R.id.txt_your_name);
  // Show soft keyboard automatically and request focus to field
  mEditText.requestFocus();
  getDialog().getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}</pre></div>



<h4 class="wp-block-heading">Solution 2</h4>



<p>In my personal experience, <strong>solution 1</strong> doesn’t always work — it’s more of a happy-case scenario. A more reliable approach is the following solution:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Java&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}">@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
  final Dialog dialog = super.onCreateDialog(savedInstanceState);
  // show the keyboard as soon we get the focus ...
  dialog.setOnShowListener(new DialogInterface.OnShowListener() {
    @Override
    public void onShow(DialogInterface dialogInterface) {
      txtInput.post(new Runnable() {
        @Override
        public void run() {
          final InputMethodManager imm = (InputMethodManager) txtInput.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
          imm.showSoftInput(txtInput, InputMethodManager.SHOW_IMPLICIT);
          txtInput.requestFocus(); // needed if you have more then one input
        }
      });
    }
  });
  return dialog;
}</pre></div>



<p>This solutions also just works with the normal <code>AlertDialog</code>&nbsp;as it uses the show listener.</p>



<p>Important to note is, that in either case <code>requestFocus</code> should either be called or set in the xml layout file for the element.</p>



<h4 class="wp-block-heading">Solution 3: Always show they Keyboard</h4>



<p>Where is allway the possibility to always show the keyboard &#8212; even if not always really useful:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Java&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}">getDialog().getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);</pre></div>



<p>The keyboard could now be shown even if the user can&#8217;t input something into any input element. Where in solution 2 the keyboard is only shown of the element gets the focus, in this case the keyboard is just shown.</p>



<h3 class="wp-block-heading">Request Focus for an Element using XML Layout File</h3>



<p>Just add the Tag <code>&lt;requestFocus /&gt;</code> to the body of the element.</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;xml&quot;,&quot;mime&quot;:&quot;application/xml&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;XML&quot;,&quot;language&quot;:&quot;XML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;xml&quot;}">&lt;EditText
    android:id=&quot;@+id/txtInput&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:inputType=&quot;text&quot;&gt;
    &lt;requestFocus /&gt;
&lt;/EditText&gt;</pre></div>



<h2 class="wp-block-heading">&nbsp;</h2>



<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sterl.org/2016/02/android-show-keyboard-by-default/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
